I’m getting this JS error while trying to use Ember routing:
Uncaught TypeError: Object <DS.Store:ember215> has no method 'create' ember-data-latest.js:3677
Ember.onLoad.app.registerInjection.injection ember-data-latest.js:3677
Ember.Application.Ember.Namespace.extend.initialize ember-latest.js:10381
Ember.Application.Ember.Namespace.extend.initialize ember-latest.js:10380
Ember.Application.Ember.Namespace.extend.initialize ember-latest.js:10379
(anonymous function) app.js:6
This is with the latest Ember.js and Ember Data from GitHub today (the master version, not the release versions). I’m aware that using the current release version can cause similar issues, but so far this seems unusual.
Looking back at those lines, it appears the Ember routing code calls an Ember Data function, and that causes the error (and prevents routing from working properly).
Are there any solutions to this yet?
jsFiddle: http://jsfiddle.net/bkjT4/2/
App = Ember.Application.create({});
App.Store = DS.Store.create({
revision: 4,
adapter: DS.RESTAdapter.create()
});
App.Router = Ember.Router.extend({
root: Ember.State.extend({
index: Ember.State.extend({
route: '/'
})
})
});
App.router = App.Router.create({
location: 'history' // does the same with hash
});
App.initialize(App.router);
Alright, the issue about the
has no method create()is because you named your storeApp.Store(uppercase String “Store”) and it is an instance. The convention in Ember.js is that you name classesUpperCaseand instanceslowerCase(see a good blog post by the emberist). This is an issue because in ember-data there is an injection registered, which automatically instantiates aStoreclass, if it is defined, see here. Long story short: if you change it to eitherApp.store = Ember.Store.create({...})orApp.Store = Ember.Store.extend({...})this issue is solved.After this has been solved, another problem arises: you are using
Ember.Stateinside yourEmber.Routerwhere you should useEmber.Routeinstead. So the final code looks like this, see http://jsfiddle.net/pangratz666/5Y2PX/: