2014-12-03 214 views
5

我使用Ember CLI和一個Rails後端設置了一個新的應用,跟在this tutorial之後,但是當我爲其中一個我收到以下錯誤消息:無效的fullName:`model:@ each`,必須是`type:name`的形式。

Error while processing route: inks.index Invalid fullName: `model:@each`, must be of the form `type:name` TypeError: Invalid fullName: `model:@each`, must be of the form `type:name` 
at __exports__.default.EmberObject.extend.resolve (http://localhost:4200/assets/vendor.js:16772:17) 
at Object.resolve [as resolver] (http://localhost:4200/assets/vendor.js:16394:25) 
at resolve (http://localhost:4200/assets/vendor.js:14930:32) 
at Object.Container.resolve (http://localhost:4200/assets/vendor.js:14510:16) 
at factoryFor (http://localhost:4200/assets/vendor.js:15013:31) 
at Object.Container.lookupFactory (http://localhost:4200/assets/vendor.js:14617:16) 
at Ember.Object.extend.modelFactoryFor (http://localhost:4200/assets/vendor.js:74810:31) 
at JSONSerializer.extend.extractArray (http://localhost:4200/assets/vendor.js:67710:22) 
at apply (http://localhost:4200/assets/vendor.js:32851:27) 
at superWrapper (http://localhost:4200/assets/vendor.js:32419:15) 

我已經搜索了一下,但我不知道它的含義。我已經檢查過,以確保我有ActiveModelAdapter和Serializer。該模型並不複雜:

我的路線是app/routes/users/index.js

​​

app/router.js

import Ember from 'ember'; 
import config from './config/environment'; 

var Router = Ember.Router.extend({ 
    location: config.locationType 
}); 

Router.map(function() { 
    this.resource('users'); 
}); 
export default Router; 

和我app/adapters/application.js是:

import DS from 'ember-data'; 

export default DS.ActiveModelAdapter.extend({ 
    namespace: 'api/v1' 
}); 

我還是漂亮的新EmberCLI,所以我不確定去哪裏看。

回答

2

所以事實證明我沒有正確使用ActiveModelSerializers。由於我列出所有用戶作爲測試,我認爲它將序列化爲我在UserSerializer中定義的序列化數據的列表。

我在我的控制器這樣做:

def index 
    @users = User.all 
    render json: @users 
end 

時,我應該根據這個一直在做的文檔(here):

def index 
    @users = User.all 
    render json: @users, each_serializer: UserSerializer 
end 

我甚至沒有注意到我的串行WASN不會被召喚。

5

我堅持類似的問題。我只用了一個差異rabl

的問題是與我Rabl的配置:

Rabl.configure do |config| 
    config.include_json_root = false 
end 

Ember.js documentation告訴我們:

The JSON payload should be an object that contains the record inside a root property

所以,你需要改變Rabl的配置:

Rabl.configure do |config| 
    config.include_json_root = true 
end 

,或者通root選項rabl模板:

collection @orders, root: 'orders' 
相關問題