Skip to content

Instantly share code, notes, and snippets.

@scart88
Forked from mynameispj/application_helper.rb
Created March 11, 2022 11:26
Show Gist options
  • Save scart88/9b18a0138a90c87a2031476cc74370cf to your computer and use it in GitHub Desktop.
Save scart88/9b18a0138a90c87a2031476cc74370cf to your computer and use it in GitHub Desktop.
Rails - Easy "active" classes for menu links in Rails
module ApplicationHelper
def current_class?(test_path)
return 'active' if request.path == test_path
''
end
end
<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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment