Question

I'm sure that this has something to do with my N00b syntax but I'm having trouble working out what it is...

I am creating a menu by looping through items in my subpages table and creating a link for each item that is returned, Like this:

<% @subpages.each do |menu| %>
<%= link_to(menu.name, {:controller => 'public', :action => "page", :id => menu.permalink }, :class => "show action footer-link") %>
<% end %>

this is working fine on the homepage of my site but if you visit one of the subpages, let's say the about us page:

http://localhost:3000/public/page/about-us

and then try to use the menu again to visit "contact us", instead of taking you to this link as i would expect:

http://localhost:3000/public/page/contact-us

It takes you to this link:

http://localhost:3000/public/page/about-us?id=contact-us

What school-boy error am I making here?

Thanks in advance.

edit: my routes

  root :to => "public#index"
  get 'admin', :to => 'access#menu'  
  get 'public/show/:permalink', :to => 'public#show'
  get 'public/page/:permalink', :to => 'public#page'
Was it helpful?

Solution 2

I managed to get it to work by passing the :permalink param to the controller instead of the ID

<% @subpages.each do |menu| %>
    <%= link_to(menu.name, { :action => "page", :permalink => menu.permalink }, :class => "show action footer-link") %>
<% end %>

OTHER TIPS

Try with this :

<% @subpages.each do |menu| %>
  <%= link_to(menu.name, page_public_path(menu.permalink), :class => "show action footer-link") %>
<% end %>

Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top