I’m trying keep a tab on a page to be selected by checking the controller.
I.e., any page that displays the Products controller should keep the Product tab selected.
I can’t seem to find the right approach.
I was considering of making a helper method, but it seems a bit tricky to put the helper into my link_to helper. Here is my guess of how I can make it work:
<%= link_to "Products", products_path, current_controller?('products') ? :class => 'selected' %>
Anyone has a better idea?
And the problem wont just be in one place, you’ll have many tabs and each tabs will have rules on which controllers+action combinations it would be active/selected for.
It’s a common problems and some people have written “plugins” for the same too.
I suggest you write helpers. Make your own mini DSL. Decide for yourself what is easy and nice to look at:
Next step, implement this method in helpers/application.rb
Have a gander at attempting the above method to your liking of course.