Skip to content

Instantly share code, notes, and snippets.

@excid3
Last active December 16, 2015 18:29
Show Gist options
  • Save excid3/5478046 to your computer and use it in GitHub Desktop.
Save excid3/5478046 to your computer and use it in GitHub Desktop.
def nav_link_to(title, url, options={})
content_tag :li, li_options(options) do
link_to title, url
end
end
def li_options(options)
link_matches? ? {class: "active"} : {}
end
def link_matches?(options)
url_matches?(options[:url]) || path_matches?(options[:path]) || controller_matches?(options[:controller], options[:action])
end
def url_matches?(url)
url == "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
end
def path_matches?(path)
path == request.fullpath
end
def controller_matches?(kontroller, action)
kontroller == params[:controller] && (action == nil || action == params[:action])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment