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
ACTIVE_CLASS = 'is-active'.freeze | |
def active_for(options) | |
name_of_controller = options.fetch(:controller) { nil } | |
name_of_action = options.fetch(:action) { nil } | |
request_path = options.fetch(:path) { nil } | |
return ACTIVE_CLASS if request_path && request_path == request.path | |
if name_of_controller == controller_name | |
ACTIVE_CLASS if name_of_action.nil? || (name_of_action == action_name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
awesome work!