Last active
December 18, 2015 20:48
-
-
Save stevenwanderski/5842397 to your computer and use it in GitHub Desktop.
Navigation helper that adds active class to current page and children
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 nav_link(link_text, link_path, include_children = true) | |
if include_children | |
class_name = request.fullpath.start_with?(link_path) ? 'active' : '' | |
else | |
class_name = current_page?(link_path) ? 'active' : '' | |
end | |
content_tag(:li, :class => class_name) do | |
link_to link_text, link_path | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment