Best way to add “current” class to nav in Rails 3

后端 未结 24 1755
天涯浪人
天涯浪人 2020-11-29 15:05

I have some static pages in a navigation menu. I want to add a class like \"current\" to the item which is currently displaying.

The way I am doing so is to add tons

24条回答
  •  攒了一身酷
    2020-11-29 15:23

    I think the best way is

    application_helper.rb:

    def is_active(controller, action)       
      params[:action] == action && params[:controller] == controller ? "active" : nil        
    end
    

    And in menu:

提交回复
热议问题