Created
May 23, 2011 13:58
-
-
Save leikind/986735 to your computer and use it in GitHub Desktop.
traversing params
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
class HashWithIndifferentAccess | |
def get_to(*keys) | |
subhash = self | |
keys.each do |k| | |
subhash = subhash.try(:[], k) | |
return nil if subhash.nil? | |
end | |
if block_given? && subhash.any? | |
yield subhash | |
else | |
subhash | |
end | |
end | |
end | |
def update | |
p params.get_to(:ad, :ad_club_availability_attributes, :foo) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment