0

我有一个 Rails 应用程序,它使用 ActiveModelSerializers(设置为使用 JSON API 格式序列化 json)和ember-datagem 来将 Ember.js 和 Ember Data 添加到资产管道。所有的 JavaScript 都是使用 CoffeeScript 编写的。

我们已将应用程序适配器设置为使用DS.JSONAPIAdapter

App.ApplicationAdapter = DS.JSONAPIAdapter.extend
  namespace: 'api/v1'

我们还设置了序列化器:

App.ApplicationSerializer = DS.JSONAPISerializer.extend()

但是,我们在尝试路由到列出模型的页面时遇到错误。

我们如何正确配置它?

4

1 回答 1

0

实际上,我们唯一需要做的就是指定应用程序适配器:

App.ApplicationAdapter = DS.JSONAPIAdapter.extend
  namespace: 'api/v1'

我们得到错误的原因是因为关联。由于模型关系中断,Ember 未能路由has_many

我们需要做的另一件事是处理带下划线的属性键。Ember DataJSONAPISerializer只知道如何映射连字符属性。我们添加了这段代码来处理映射:

DS.JSONAPISerializer.reopen
  keyForAttribute: (key) ->
    Ember.String.underscore(key)

  keyForRelationship: (key) ->
    Ember.String.underscore(key)
于 2015-08-21T19:49:03.430 回答