使用JSONAPI适配器从Emberjs发布到Rails,Rails没有看到参数 [英] Post to Rails from Emberjs using JSONAPI adapter, Rails not seeing the params
本文介绍了使用JSONAPI适配器从Emberjs发布到Rails,Rails没有看到参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的帖子到rails以正确的控制器和动作作为帖子,但是如果我用Pry看着内部的数据属性,那里。
我的有效载荷:
{data:{attributes:{body:Why user_id:17},relationships:{user:{data:null},conversation:{data:null}},type:messages}}
内容类型:应用程序/ vnd.api + json
Rails控制台:
{format=>json,controller=>api / v1 / messages ,action=>create}
解决方案
所以这可能会帮助其他人。
您需要添加对JSONAPI的MIME类型的支持。
添加到config / initializers / mime_types.rb
Mime :: Type.registerapplication / json,:json, %w(text / x-json application / jsonrequest application / vnd.api + json)
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"}
解决方案
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 )
这篇关于使用JSONAPI适配器从Emberjs发布到Rails,Rails没有看到参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文