Skip to content

Instantly share code, notes, and snippets.

@gingerhot
Forked from mynameispj/application_helper.rb
Created March 19, 2018 07:20
Show Gist options
  • Save gingerhot/10b70c005a68fdccdf7e2bb462330215 to your computer and use it in GitHub Desktop.
Save gingerhot/10b70c005a68fdccdf7e2bb462330215 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