6

我正在尝试在 Emberjs 中保存消息模型。我正在使用 JSONAPIAdapter 和 JSONAPISerilzier。

我发布到 Rails 的帖子作为帖子点击了正确的控制器和操作,但如果我用 Pry 往里面看,数据属性不存在。我的有效载荷:

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

Content-Type:application/vnd.api+json

Rails 控制台中的 Rails 参数:

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

1 回答 1

11

所以这可能会帮助其他人。

您需要添加对 JSONAPI 的 mime 类型的支持。

将此添加到 config/initializers/mime_types.rb

Mime::Type.register "application/json", :json, %w( text/x-json application/jsonrequest application/vnd.api+json )
于 2015-08-14T15:12:31.277 回答