我有一个Rails应用程序,它使用ActiveModelSerializers (设置为使用json API格式序列化JSON )和Ember gem将Ember.js和ember-data数据添加到资产管道中。所有的JavaScript都是使用CoffeeScript编写的。
我们已将应用程序适配器设置为使用DS.JSONAPIAdapter
App.ApplicationAdapter = DS.JSONAPIAdapter.extend
namespace: 'api/v1'我们还设置了序列化程序:
App.ApplicationSerializer = DS.JSONAPISerializer.extend()然而,当我们试图路由到列出模型的页面时,我们得到了错误。
我们如何才能正确地配置它?
发布于 2015-08-22 03:49:03
实际上,我们唯一需要做的就是指定应用程序适配器:
App.ApplicationAdapter = DS.JSONAPIAdapter.extend
namespace: 'api/v1'我们得到一个错误的原因是因为关联。由于模型上的has_many关系中断,Ember路由失败。
我们需要做的另一件事是处理下划线的属性键。Ember Data's JSONAPISerializer only knows how to map hyphenated attributes。我们添加了以下代码来处理映射:
DS.JSONAPISerializer.reopen
keyForAttribute: (key) ->
Ember.String.underscore(key)
keyForRelationship: (key) ->
Ember.String.underscore(key)https://stackoverflow.com/questions/32147124
复制相似问题