Created
February 16, 2015 14:28
-
-
Save mikecmpbll/d4a048d69b03069be161 to your computer and use it in GitHub Desktop.
active?
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
# # # | |
# If you pass: | |
# - String, then it highlight for that controller name | |
# - Array, then it will highlight for those actions | |
# - Hash, then it will highlight for only those controller and action combinations | |
# | |
def is_active?(controller_action_hash_or_array_or_string) | |
controller = params[:controller] | |
action = params[:action] | |
controller_action_hash = | |
case controller_action_hash_or_array_or_string | |
when Array | |
{ controller => controller_action_hash_or_array_or_string } | |
when String | |
{ controller_action_hash_or_array_or_string => nil } | |
when Hash | |
controller_action_hash_or_array_or_string | |
else | |
raise ArgumentError, "what are you even ..." | |
end | |
controller_action_hash = Hash[controller_action_hash.map{|k,v| [k, [v || action].flatten]}] | |
"active" if controller_action_hash.key?(controller) && controller_action_hash[controller].include?(action) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment