How to get current controller for a URL in Rails?

Posted by valk on Stack Overflow See other posts from Stack Overflow or by valk
Published on 2012-06-30T15:14:02Z Indexed on 2012/06/30 15:15 UTC
Read the original article Hit count: 155

I'm using this code to highlight currently active menu tab with Twitter Bootstrap:

  def nav_link_to(link_text, link_path, options = nil)
    class_name = current_page?(link_path) ? 'active' : ''

    content_tag(:li, :class => class_name) do
      link_to link_text, link_path, options
    end
  end

This of course makes the link active, only if the given link IS the current page. How can I change this function, such that it would return 'active' for any links below current controller? In other words, for all actions for Posts controller, the links would be active? Thanks.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about menu