I'm trying to debug a problem where Rails isn't decoding the JSON POST data.
The server logs show:
2011-12-14T06:44:44+00:00 app[web.2]: Started POST
2011-12-14T06:44:44+00:00 app[web.2]: Processing by PostsController#create as */*
2011-12-14T06:44:44+00:00 app[web.2]: Parameters: {"{\"athlete_id\":\"\",\"known_as\":\"abc\",\"email\":\"abc@defg.com\",\"result\":\"112233\",\"rx\":false,\"mods\":\"thkjth\",\"notes\":\"\"}"=>nil, "affiliate_id"=>"testaffiliate", "wod_id"=>"12345"}
Note that the JSON string is not being parsed - Rails is assigning it as a key in the hash, pointing to a nil value. Does anyone have any ideas before I write a before_filter that tries to JSON.parse all of the params keys?
I don't think this is relevant since I'm sending and receiving data okay, but this problem occurs during a CORS Request from IE (using XDomainRequest).
You can get past this by setting the Content-Type header to "application/json". You can let the controller know what it expects to return with the Accept header set to "application/json".
The following command with both headers:
Generates this in the logs:
This command with the Accept header:
Generates these logs:
And finally this command with the Content-Type header:
Generates these logs:
Notice the parsed parameters and processing message change subtly with each header type.
For Thin:
For Unicorn and Phusion Passenger: