I am trying to push keys and values into a hash as I iterate through some params passed into my controller. The snipper of code below creates an array of hashes, but I want hashes with multiple key value pairs. How do I do this?
@diff_attr = []
params[place_type].each_pair do |k, v|
@diff_attr << {k.to_sym=>v}
end
I should change my @diff_attr to be a hash: @diff_attr = { }, but after this, I’m not sure how to pass the key and value inside my iterating block.
Currently, if I puts @diff_attr, I get something like:
{:name => "blah blah"}, {:age => "24"}
but I want something more like:
{:name=>"blah blah", :age=>"24"}
1 Answer