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

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

    Basic, No Helper

    <%= content_tag(:li, class: ('active' if request.path == '/contact')) do %>
        <%= link_to 'Contact', '/contact' %>
    <% end %>
    

    I use this since I have more than one class -

    <%= content_tag(:li, class: (request.path == '/contact' ? 'active black' : 'black')) do %>
        <%= link_to 'Contact', '/contact' %>
    <% end %>
    

提交回复
热议问题