How to get Twitter-Bootstrap navigation to show active link?

前端 未结 22 2087
一整个雨季
一整个雨季 2020-11-27 09:31

I\'m not understanding how Twitter Bootstrap does active links for the navigation. If I have a regular navigation like this (with ruby on rails linking):

<         


        
22条回答
  •  -上瘾入骨i
    2020-11-27 10:08

    Here's what I did:

    I created a ViewsHelper and included in ApplicationController:

    include ViewsHelper
    

    Inside ViewsHelper I created a simple method like this:

    def page_state(path)
      current_page?(path) ? 'active' : ''
    end
    

    In my view I do this:

  • <%= link_to 'Foobars', foobar_path %>
提交回复
热议问题