user2824854
user2824854

Reputation:

Ember.js: Cannot set property 'store' of undefined

I am creating an Ember.js application with RESTful API and I ran into this error:

Error while loading route: TypeError: Cannot set property 'store' of undefined

I can't figure out what is causing this.

window.App = Ember.Application.create();

App.VideosAdapter = DS.MyRESTAdapter;

App.Router.map(function () {
    this.resource('videos', {
        path: '/'
    });
});

App.Video = DS.Model.extend({
    title: DS.attr('number'),
    videoId: DS.attr('string'),
    date: DS.attr('string')
});

App.VideosAdapter = DS.RESTAdapter.extend({
    namespace: 'data'
});

App.VideosRoute = Ember.Route.extend({
    model: function() {
        return this.store.find();
    }
});

Debug info:

DEBUG: -------------------------------
DEBUG: ember.js:3880
DEBUG: Ember      : 1.7.0-beta.1+canary.2eae2280 ember.js:3880
DEBUG: Ember Data : 1.0.0-beta.7+canary.20adb1d5 ember.js:3880
DEBUG: Handlebars : 1.3.0 ember.js:3880
DEBUG: jQuery     : 1.10.2 ember.js:3880
DEBUG: ------------------------------- 

I tried to change my route like this:

App.VideosRoute = Ember.Route.extend({
    model: function() {
        return App.Video.find();
    }
});

But got an error:

Error while loading route: TypeError: Object function () { .. } has no method 'find'

This is my JSON data (http://localhost/data/videos/1) (it loads fine into Ember Inspector):

{
    "video": {
       "id": 1,
       "title": "Video title!",
       "videoId": "AAZ23",
       "date": "12/122013"
    }
}

Upvotes: 0

Views: 1716

Answers (1)

Steve H.
Steve H.

Reputation: 6947

You have to tell the store what kind of object you want-- try this:

App.VideosRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('video');
    }
});

Upvotes: 1

Related Questions