Skip to content

Instantly share code, notes, and snippets.

@stevenwanderski
Last active December 18, 2015 20:48
Show Gist options
  • Save stevenwanderski/5842397 to your computer and use it in GitHub Desktop.
Save stevenwanderski/5842397 to your computer and use it in GitHub Desktop.
Navigation helper that adds active class to current page and children
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