Skip to content

Instantly share code, notes, and snippets.

@olimart
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olimart/64db256e715a3975066a to your computer and use it in GitHub Desktop.
Save olimart/64db256e715a3975066a to your computer and use it in GitHub Desktop.
Current Page Active
module ApplicationHelper
def is_active?(link_path)
current_page?(link_path) ? "active" : ""
end
end
<li class="<%= is_active?(some_path) %>">
<%= link_to "name path", some_path %>
</li>
====================================
module ApplicationHelper
def cp(path)
current_route = Rails.application.routes.recognize_path(path)
"current" if current_page?(path) or params[:controller] == current_route[:controller]
end
end
<nav id="menu-panel">
<%= link_to 'SERVICES', services_path, class: cp('/services') %>
<%= link_to 'FACILITIES', facilities_path, class: cp('/facilities') %>
<%= link_to 'ABOUT', about_path, class: cp('/about') %>
<%= link_to 'CAREERS', careers_path, class: cp(careers_path) %>
<%= link_to 'BLOG', blog_index_path, class: cp(blog_index_path) %>
<%= link_to 'CONTACT', contact_path, class: cp('/contact') %>
<a href="#" id="close-menu-panel"><b>CLOSE</b></a>
</nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment