I'm setting up a new app with Ember CLI and a Rails backend following this tutorial but when I set up a 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've googled around, but I have no idea what it even means. I've checked to make sure I have ActiveModelAdapter and Serializer. The model is not complicated:
My route is 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
is:
import DS from 'ember-data';
export default DS.ActiveModelAdapter.extend({
namespace: 'api/v1'
});
I'm still pretty new with EmberCLI so i'm not really sure where to look.
I stuck with similar issue. Only one difference I was used rabl.
The problem was with my rabl configuration:
Rabl.configure do |config|
config.include_json_root = false
end
Ember.js documentation tells us:
The JSON payload should be an object that contains the record inside a root property
So, you need to change rabl configuration to:
Rabl.configure do |config|
config.include_json_root = true
end
or, pass root
option inside rabl
template:
collection @orders, root: 'orders'
So it turns out I wasn't using ActiveModelSerializers correctly. Since I was listing all users as a test I thought it would serialize as a list of the serialized data I defined in UserSerializer.
I was doing this in my controller:
def index
@users = User.all
render json: @users
end
When I SHOULD have been doing this according to the docs (here):
def index
@users = User.all
render json: @users, each_serializer: UserSerializer
end
I didn't even notice my serializer wasn't being called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With