Post to Rails from Emberjs using JSONAPI adapter,

2019-06-22 15:37发布

问题:

I am trying to save a message model in Emberjs. I am using the JSONAPIAdapter and JSONAPISerilzier.

My post to rails hits the right controller and action as a post, but if I look inside with Pry, the data attributes are not there. My payload:

{"data":{"attributes":{"body":"Why","user_id":"17"},"relationships":{"user":{"data":null},"conversation":{"data":null}},"type":"messages"}}

Content-Type:application/vnd.api+json

Rails params in the Rails console:

{"format"=>"json", "controller"=>"api/v1/messages", "action"=>"create"}

回答1:

So this may help someone else out.

You need to add support for the mime type for JSONAPI.

Add this to config/initializers/mime_types.rb

Mime::Type.register "application/json", :json, %w( text/x-json application/jsonrequest application/vnd.api+json )