Post to Rails from Emberjs using JSONAPI adapter, Rails not seeing the params

断了今生、忘了曾经 提交于 2019-12-23 12:21:07

问题


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 )


来源:https://stackoverflow.com/questions/32006492/post-to-rails-from-emberjs-using-jsonapi-adapter-rails-not-seeing-the-params

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!