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

后端 未结 24 1789
天涯浪人
天涯浪人 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:35

    Use the current_page? helper to determine whether or not you should assign the "current" class. For example:

    <%= 'active' if current_page?(home_about_path) %>
    

    Note you can also pass a path (not only a hash of options), e.g: current_page?(root_path).

提交回复
热议问题