psharma
psharma

Reputation: 1289

A good way of setting up navigation bar/links in rails

I am wondering what is a good way of setting navigation links for different pages in rails ? Right now what I have breaks. Here is the code

_nav.html.erb

<ul class="nav nav-pills pull-right">
    <%if current_page?(:action => 'new') %>
    <li><%= link_to "Home", root_path%></li>
    <%elsif current_page?(:controller => 'home', :action => 'index') %>
    <li><%= link_to "Contact", home_contact_path%></li>
    <%end%>
</ul>

So when I do a <%= render :partial => 'layouts/nav' %> under /views/home/index.html.erb It gives me an error

No route matches {:action=>"new", :controller=>"home"}

Upvotes: 1

Views: 3555

Answers (1)

gabrielhilal
gabrielhilal

Reputation: 10769

You have no action new in your home controller... Looking at your routes, the only action available is contact...

Try to use helpers (current_page?(helper)) instead of action + controller. Check the rake routes to see the helpers.

_nav.html.erb

<ul class="nav nav-pills pull-right">
  <%if current_page?(new_user_registration) %> #check the path helper by `rake routes`
    <li><%= link_to "Home", root_path%></li>
  <%elsif current_page?(root_path) %>
    <li><%= link_to "Contact", home_contact_path%></li>
  <%end%>
</ul>

Upvotes: 2

Related Questions