Skip to content

Instantly share code, notes, and snippets.

@mrdougwright
Created May 30, 2017 19:30
Show Gist options
  • Save mrdougwright/cd5812de10911035172a97860b6f6902 to your computer and use it in GitHub Desktop.
Save mrdougwright/cd5812de10911035172a97860b6f6902 to your computer and use it in GitHub Desktop.
Rails Expanded_Key
def expanded_key(key) # :nodoc:
return key.cache_key.to_s if key.respond_to?(:cache_key)
case key
when Array
if key.size > 1
key = key.collect{|element| expanded_key(element)}
else
key = key.first
end
when Hash
key = key.sort_by { |k,_| k.to_s }.collect{|k,v| "#{k}=#{v}"}
end
key.to_param
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment