Skip to content

Instantly share code, notes, and snippets.

@twe4ked
Created July 13, 2011 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twe4ked/1079479 to your computer and use it in GitHub Desktop.
Save twe4ked/1079479 to your computer and use it in GitHub Desktop.
# 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