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

前端 未结 22 2182
一整个雨季
一整个雨季 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:13

    Shortest code 

    This deals with BOTH nav, and sub nav list elements. You can pass either an array a single path and will deal with both.

    application_helper

    # Active page method
    def ap(p:);'active' if p.class == Array ? p.map{|m| current_page? m}.any? : (current_page? p) end
    

    view (html.erb)

    
    

提交回复
热议问题