I am building an iOS app and it needs to post to a RoR API.
To test the POST, I am running this command:
curl -d @/tmp/data localhost:3000/api/ratings
Where /tmp/data contains an array of hashes:
[ { "uid": "gilt_162929239", "rate": 1 } ]
In Ruby, params looks like this:
[1] pry(#<Api::PromotionRatingsController>)> params
=> {" { \"uid\": \"good_162929239\", \"rate\": 1 } "=>nil,
"format"=>"json",
"action"=>"create",
"controller"=>"api/ratings"}
How do I get Rails to create the array of hashes for me to iterate over with each?
Edit: I see I was missing headers.
Adding to the curl command line:
--header "Accept: application/json" --header "Content-type: application/json"
Now, here are my params:
[1] pry(#<Api::PromotionRatingsController>)> params
=> {"_json"=>[{"uid"=>"good_162929239", "rate"=>1}],
"format"=>"json",
"action"=>"create",
"controller"=>"api/ratings",
"promotion_rating"=>{"_json"=>[{"uid"=>"good_162929239", "rate"=>1}]}}
Still not right.
According to this:
So, my guess is that you either need to include a root element, or set
config.wrap_parameters.