Invalid full name: `model: @ each`, must be of type` type: name`

I am setting up a new application with the Ember CLI and Rails backend after this tutorial , but when I set up the route for one of my models, I get the following error:

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) 

I searched googled, but I have no idea what that means. I checked to make sure that I have ActiveModelAdapter and Serializer. The model is not complicated:

My route app/routes/users/index.js :

 import Ember from 'ember'; export default Ember.Route.extend({ model: function() { return this.store.find('user'); } }); 

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; 

and my app/adapters/application.js :

 import DS from 'ember-data'; export default DS.ActiveModelAdapter.extend({ namespace: 'api/v1' }); 

I'm still pretty new with EmberCLI, so I'm not sure where to look.

+5
source share
2 answers

So it turned out that I did not use ActiveModelSerializers correctly. Since I listed all users as a test, I thought it would be serialized as a list of serialized data defined in UserSerializer.

I did this in my controller:

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

When I SHOULD do this according to the docs ( here ):

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

I did not even notice that my serializer was not called.

+2
source

I stuck with a similar problem. Only one difference I used rabl .

The problem was in my rabl configuration:

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

The Ember.js documentation tells us:

The JSON payload must be an object containing an entry inside the root property

So you need to change the rabl configuration to:

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

or, pass the root parameter inside the rabl template:

 collection @orders, root: 'orders' 
+5
source

Source: https://habr.com/ru/post/1208306/


All Articles