Last active
December 16, 2015 18:29
-
-
Save excid3/5478046 to your computer and use it in GitHub Desktop.
This file contains 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
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