On 2/22/07, Ryan Felton <[EMAIL PROTECTED]> wrote:
I have a tab navigation and I'm trying to set the active tab based on
the page that the customer is viewing. Currently its a bunch of if
else statements, but I know there has to be a way to shorten it.
<% if request.symbolized_path_parameters[:controller] == 'main' %>
<%= link_to 'Home', {:controller => 'main', :action => 'show' },
:class => 'active' %>
<% else %>
<%= link_to 'Home', {:controller => 'main', :action => 'show' } %>
<% end %>
Another approach to this is to do it all with CSS. You can set the
current controller as the body id and the current action as a class in
the body, and each tab can have a specific id. Then, in your CSS file
you can style the tabs accordingly, like:
body#main.show a#home { background-color: #790619; }
something along those lines. this can get unwieldy if there's tons of
navigation, but for a "normal" amount I've found it works pretty well
and keeps the view code cleaner.
toby
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby