This post is very much similar to the post of Abhijit.

[Highlight the active page (Highight the active page)][1] by Abhijit.

This would work very well if we have simpler routes, if we have complex routes(Modular routes) in our app where we have similar urls with same action then we need to enhance this approach. For e.g There are three links on the same page as follows.




All these are pointing to same action. i.e Dashboard. So selecting active tab based on action name will fail here and will highlight all three links.

So I camp up with an alternative solution to my problem. May be this is not the best. But this worked. And it may help you guys.

  def is_active?(path)
    # 'active' is the class highlighting class of the CSS
    @active ||= { request.path => 'active' } 
  = link_to 'All', *_path, :class => is_active?(*_path)


This will not work with *_url helpers as we are using the

in our helper.

If you have any thoughts or queries feel free give comments.