My Rails app has a player class that works perfectly. Players can be created, deleted, and updated from my rails control panel without any issues.
I would like a remote
First of all, I think your data format is ok and is not the problem here. When I ran exactly into the same problem it was because I did not send the Content-Type: application/json
header along with my request.
In Postman, you can select the 'raw' data format and then 'JSON (application/json)' to include this header. In my case it looks like this:
Alternatively, you can also try it with curl
(source):
curl -X POST -H "Content-Type: application/json" -d '{"player": {"name": "test","room_id": 0,"skin_id": 1,"head_id": 2,"torso_id": 3,"legs_id": 4,"x_position": 5,"y_position": 6,"direction": 7,"action": "","gender": "f"}}' localhost:3000/players.json
If you omit the -H "Content-Type: application/json"
, then you will receive a 400 response with the "param not found" error, if you include it it should work.
If you are trying this:
via Postman - Under form-data tab, you need to have the vars as :
player[name]
player[room_id]
.
.
via jQuery:
$.ajax({ url: 'url', type: 'post', data: { player: { name: 'Test', room_id: '0' } } })