Forum: Ruby on Rails handling navigation tabs - use sessions?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jason P. (Guest)
on 2006-05-16 00:04
I think this is a fairly easy question done several times in several
languages, but on a traditional 'tab' based navigation webpage, what's
the best way to handle the active state?

I am using this in my view:

<% for category in @categories %>
   <% if the condition is met to make this the active tab %>
      <li><a id='active' href='#'><%= %></a></li>
   <% else %>
      <li><a href='#'><%= %></a></li>
   <% end %>
<% end %>

@categories are all user defined in the database.  Is the best way to
handle this by setting up a session variable that tracks it?
Adam D. (Guest)
on 2006-05-16 16:58
(Received via mailing list)
you can also put something in your /config/routes.rb to add another
like :page

for example if your tabs all prefix with '/nav' or something you can do

map.connect '/nav/:page', :controller => "content", :action => "index"

then in the view you can do something like this inside your href to make

<a href="/nav/tabname/" <%= "id='current'" if params[:page] == 'tabname'

This topic is locked and can not be replied to.