jeudi 19 mai 2016

Rails nesting static routes

I have several static pages (About, Contact, Help) that are mapped in the routes.rb file like this:

get 'about', to: 'static#about', as: 'about'
get 'contact', to: 'static#contact', as: 'contact'
get 'help', to: 'static#help', as: 'help'

They are accessed in the layout partial, _footer.html.erb from this code:

<%= link_to "About", 'about_path', :class => '' %>
<%= link_to "Contact", 'contact_path',  :class => '' %>
<%= link_to "Help", 'help_path', :class => '' %>

Everything works fine until I click on the footer links while I'm in a nested route like /users/current/edit (where I might edit my user-profile). For example, when I click on the ABOUT link at the bottom of the page, I would expect to be taken directly to the static#about route at about_path.

However, I am getting an ActionController exception (in development) and a page not found in production. It's trying to map to /users/current/about_path.

Any ideas on how to fix this?

Aucun commentaire:

Enregistrer un commentaire