Add an 'active' class to all active links in rails?

后端 未结 7 683
醉酒成梦
醉酒成梦 2021-02-05 15:08

Basically, I have a lot of code that looks like this:

link_to t(\'.profile\'), business_path(@business), class: \'#{\'active\' if current_page? business_path(@bu         


        
7条回答
  •  無奈伤痛
    2021-02-05 15:43

    I faced same requirement and here is my solution.

    Create a method within ApplicationHelper

    def active_class(link_path)
        current_page?(link_path) ? "active" : ""
    end
    

    And inside your view:

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