Monday, 9 September 2013

access a hash in ruby not working

access a hash in ruby not working

after i preform this:
data = JSON.parse(params[:photo].to_json)
puts data gives me this {"location"=>"russia", "userid"=>"0011"}
however I tried all the ways of accessing this. data[:location] or
data["location"] or data[1] I understand what a hash is, and how to work
with such things in other languages, but stuck. Any help?
data["location"] output:
TypeError (no implicit conversion of String into Integer):
app/controllers/sendphoto_controller.rb:5:in `[]'
app/controllers/sendphoto_controller.rb:5:in `create'

No comments:

Post a Comment