Highlight tab in menu

前端 未结 5 1766
甜味超标
甜味超标 2020-12-28 18:51

I have a menu which is a ul

Home | Calendar | Settings

I want to highlight (via a css class) the selected tab in the menu.

Some lin

5条回答
  •  囚心锁ツ
    2020-12-28 19:40

    In your helper file:

    def is_active?(page_name)
      "active" if params[:action] == page_name
    end
    

    In the template file:

    link_to 'Home', '/', :class => is_active?("index")
    link_to 'About', '/about', :class => is_active?("about")
    link_to 'contact', '/contact', :class => is_active?("contact")
    

    I found this on: http://juliocapote.com/post/52081481/highlight-link-based-on-current-page-in-rails

提交回复
热议问题