Created
September 21, 2011 09:28
-
-
Save corroded/1231654 to your computer and use it in GitHub Desktop.
Adds current class to link if on the current page
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 link_to_with_current(*args) | |
html_class = args[2][:class] if args[2] | |
path = args[1].is_a?(Array) ? polymorphic_path(args[1]) : args[1] | |
if current_page?(path) | |
if html_class.nil? | |
html_class = "current" | |
else | |
html_class << " current" | |
end | |
if args[2] | |
args[2]['class'] = html_class | |
else | |
args << {:class => html_class} | |
end | |
end | |
link_to(*args) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment