Skip to content

Instantly share code, notes, and snippets.

@briancollins
Created March 12, 2011 01:10
Show Gist options
  • Save briancollins/866899 to your computer and use it in GitHub Desktop.
Save briancollins/866899 to your computer and use it in GitHub Desktop.
link_to with an "active" class for links to the current page
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
@briancollins
Copy link
Author

Probably needs to handle link_tos with an existing :class attribute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment