Created
March 12, 2011 01:10
-
-
Save briancollins/866899 to your computer and use it in GitHub Desktop.
link_to with an "active" class for links to 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_active(*args, &block) | |
if block_given? | |
options = args.first || {} | |
html_options = args.second | |
link_to_active(capture(&block), options, html_options) | |
else | |
name = args[0] | |
options = args[1] || {} | |
html_options = args[2] | |
link_to_unless_current(name, options, html_options) do | |
link_to(name, options, html_options.try(:merge, :class => :active) || {:class => :active}) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Probably needs to handle link_tos with an existing :class attribute