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

前端 未结 22 2124
一整个雨季
一整个雨季 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条回答
  •  爱一瞬间的悲伤
    2020-11-27 10:21

    You may define a helper method in application_helper.rb

    def create_link(text, path)
      class_name = current_page?(path) ? 'active' : ''
    
      content_tag(:li, class: class_name) do
        link_to text, path
      end
    end
    

    Now you can use like:

    create_link 'xyz', any_path which would render as

  • xyz
  • Hope it helps!

提交回复
热议问题