Last active
August 29, 2015 14:13
-
-
Save olimart/64db256e715a3975066a to your computer and use it in GitHub Desktop.
Current Page Active
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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