Created
January 20, 2019 06:58
-
-
Save dhamkur/cc88e816016cddcf19e07d43bd9e9671 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