Wednesday, May 11, 2011

How to highlight tabs in Rails

1) Include the following method in application helper.

def is_active?(page_name)
#"lllllllllllll #{page_name}")
#"cccccccccccccc #{params[:controller]}")
"current" if params[:controller] == page_name

2) In your layout, add this:

<%= link_to 'Articles', new_article_path, :class => is_active?("articles") %>

3) Uncomment the logger lines to see which controller is handling the request and just fill in
the parameters for is_active? method

Fixed an error from the code I found from an original post in Stackoverflow.