Get hash key and convert into string ruby -
Get hash key and convert into string ruby -
example hash
hash = {:key => ["val1", "val2]}
when did on rails 3.0.7, fine.
> hash.keys.to_s => "key" > hash[hash.keys.to_s] => ["val1", "val2"]
but if rails 3.1.3, isn't.
> hash.keys.to_s => [\"key\"] > hash[hash.keys.to_s] => nil
is because of rails version changed? , is there other way turn hash key string works both version (or rails 2 too)?
did upgrade ruby rails? think alter between 1.8 , 1.9
try hash.keys.first.to_s
(if there's 1 key) or hash.keys.join
ruby-on-rails-3
Comments
Post a Comment