Created
January 5, 2018 18:18
-
-
Save ismarsantos/b3b747324277939a0d967f71eb7cdd00 to your computer and use it in GitHub Desktop.
Ruby on Rails. Class "active" for menu items based on Path or Controller and Action names
This file contains hidden or 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
module ApplicationHelper | |
def active_for(options = {}) | |
name_of_controller = options[:controller] || nil | |
name_of_action = options[:action] || nil | |
request_path = options[:path] || nil | |
if request_path.nil? | |
if (name_of_action.nil? or name_of_action == action_name) and | |
name_of_controller == controller_name | |
'active' | |
else | |
'' | |
end | |
else | |
request_path == request.path ? 'active' : '' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment