Ruby has an intersting problem with accessing Hashes with Symbols vs
Strings. Right now Symbols and Strings are in fact two different
objects.
Rails took an effort to eliminate this disparity through
HashWIthIndiferentAccess, which will take :key or ‘key’ and make sure it
points to the same value.
WTF? Is it unreasonable for me to expect the value of a params hash
element to be String?
Params in rails can be multi level; that is, on the rhtml page they
may b e something along the lines of "foo[bar][baz][bleh]=10, which
gets translated to the params value as a hash*. And, I think because
you can use symbols or strings as the Hash keys, is why it’s
HashWithIndifferentAccess.
If the value was always a scalar string, you wouldn’t be able to new()
objects with params. (Well, you could if you chose another
serialization scheme than turning it into a hash, but a hash seems
reasonable.)
If I’m recalling correctly, the hash for the above would be
something along the lines of params = {:foo =>{:bar => {:baz =>{:bleh
=> 10}}}}
–
If you stick a screwdriver in your eye don’t expect the manufacturer
to make you wealthy, instead try being more careful. – Unknown
So you see one of the values in that hash is a string but another is
a nested hash. I think this is what is causing you confusion. You
need to write that method in a recursive way to it traverses the sub
hashes as well as the top level ones