Ruby on Rails – Easy Navigation Nov
19

This is primarily going to be a repost to some extent but would like to add a piece that I think will help even more. Based on http://www.cuberick.com/2010/05/simple-tabbed-navigation-in-rails.html I have added a simple regex that I think will help with the current status and be flexible to change on the fly if rules change.

<ul>
<li class="<%= selected_navigation(:items) %>"><%= link_to "Items", items_path %></li>
<li class="<%= selected_navigation(:things) %>"><%= link_to "Things", things_path %></li>
</ul>

and then add in the ApplicationHelper this simple code

  def selected_navigation(element)
    request.fullpath =~ /\/#{element.to_s}/ ? "current" : ""
  end

Leave a comment