Created
March 20, 2018 09:11
-
-
Save pawelztef/d973cacf409d8c8ae82745661dfcd1d8 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 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