For instance class="active" will be located on the first, second
lines, depending on the action.
application.html.erb:
<li class="active">
things.each_with_index do |thing, index|
<li <%= 'class="active"' if index == 2 and params[:action] == 'foo' %>
>Tasks</li>
That's just the sketch of the behaviors - but you must clean it up. The 2
and the 'foo' should appear in a table, preferably inside the thing model.
Controllers should have the minimum possible logical statements, and View
should have less.
def get_class(active_action)
"active" if @active_action == active_action
end
then in your actions set the @active_action variable
for your default, you could set the @active_action in the
application.rb controller, then it will be overwritten if some action
specifically overrides the variable
If you are trying to highlight the active tab a good way of doing it is
by giving all the tabs an id as well as a body id for each of the pages
that the tabs exist on. Once you do this you have control of the active
tab style.