Created
July 13, 2011 00:11
-
-
Save twe4ked/1079479 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
# link_to 'Foo', bar_path, :class => active_link?('some_controller', 'some_action') | |
# link_to 'Foo', bar_path, :class => active_link?('some_controller') # Active anywhere within the controller | |
def active_link?(controller, action = nil) | |
action_match = case | |
when action.nil? then true | |
when action.is_a?(Array) then action.include? params[:action] | |
else action == params[:action] | |
end | |
params[:controller] == controller && action_match ? 'active ' : '' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment