0

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"
    }
}
1
  • Not sure this link is helpful: (emberjs.com/api/data/classes/DS.Adapter.html). Looks like you're creating a custom adapter which you then need to assign to the store according to the docs (apologies if I'm totally off here!) Commented Apr 4, 2014 at 0:04

1 Answer 1

1

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');
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.