Skip to content

Instantly share code, notes, and snippets.

@spac3unit
Forked from mynameispj/application_helper.rb
Created May 27, 2019 14:36
Show Gist options
  • Select an option

  • Save spac3unit/a8a42726c5d01a0d45fdab1c0254ef19 to your computer and use it in GitHub Desktop.

Select an option

Save spac3unit/a8a42726c5d01a0d45fdab1c0254ef19 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