I deal w/ this all the time. Right now I've settled on this:

def navigation_link_to(name, url={}, active=false)
    link_to(name, url, {:class => "nav_item#{" active" if active}"})
 end

similar to a regular link_to method, but pass whatever I want at the end to determine whether or not the tab should be active. i do this b/ c what makes the tab active is not always consistent. sometimes its the controller, sometimes its the action, sometimes its something arbitrary.

On Feb 22, 2007, at 10:08 PM, Ryan Felton 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 %>

Thanks,

Ryan
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

Reply via email to