GuillermoParedes
2/7/2018 - 7:18 PM

Rails - Easy "active" classes for menu links in Rails

Rails - Easy "active" classes for menu links in Rails

<nav class="subnav">
  <ul>
    <li><%= link_to "account stats", account_path, :class => current_class?(account_path)  %></li>
    <li><%= link_to "payment information", '/account/payment', :class => current_class?('/account/payment')  %></li>
    <li><%= link_to "profile settings", profile_path, :class => current_class?(profile_path) %></li>
  </ul>
</nav>
module ApplicationHelper

  def current_class?(test_path)
    return 'active' if request.path == test_path
    ''
  end

end