2
votes

I'm getting this error when trying to load a set of records through a restful api. It works with ember-model but when I switch to ember-data (beta 2) and ember.js (1.0), I get this error.

Assertion failed: No model was found for '0'

App.ApplicationAdapter = DS.RESTAdapter.extend({
  host: 'http://localhost:8080',
  namespace: 'api'
});


App.Router.map(function() {
  this.resource('about');
  this.resource('pages', function() {
      this.resource('page', { path: ':page_id' });
  });
this.resource('login');
});

App.AuthenticatedRoute = Ember.Route.extend({
  actions: {
     error: function(reason, transition) {
      if (reason.status == 403) {
          alert('You must login');
          this.transitionTo('login');
      }
      else {
          //alert('non 403 error:'+reason.status);
          this.transitionTo('login');
      }
     }
  }
});


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

App.PageRoute = Ember.Route.extend({
  model: function(params) {
    return this.store.find('page', params.page_id);
  }
});

App.Page = DS.Model.extend({
  user: DS.attr('string'),
  slug: DS.attr('string'),
  zcontent: DS.attr(),
  title: DS.attr('string'),
  create_time: DS.attr('date'),
  update_time: DS.attr('date')
});

Here is what the backend returned:

{
    "pages": [
        {
            "update_time": "2013-01-14 19:59:35.744855",
            "title": "",
            "id": 38,
            "create_time": "2012-08-04 15:08:16",
            "user": "robert-jones",
            "slug": "orange"
        },
        {
            "update_time": "2013-01-14 19:59:35.899830",
            "title": "",
            "id": 47,
            "create_time": "2012-08-03 10:04:07",
            "user": "robert-jones",
            "slug": "REVIEWStheraputics"
        },
        {
            "update_time": "2012-12-18 07:16:13.656509",
            "title": "'Notes on Temperature Heat Map'",
            "id": 17,
            "create_time": "2012-12-18 07:14:48.118119",
            "user": "robert-jones",
            "slug": "50612c27b94ca650"
        },
        {
            "update_time": "2012-12-12 19:48:08.079021",
            "title": "'Notes on Dyanmic Heat Map'",
            "id": 8,
            "create_time": "2012-12-12 19:48:08.013336",
            "user": "robert-jones",
            "slug": "c5642b4c14d901cf"
        }
    ]
}
1
Little more information as to when and where you are getting error will be helpful.Gautham
How does the JSON returned from the backend look like?intuitivepixel
I added the results from the backend. See aboveuser1629165

1 Answers

2
votes

I've run into this before when my server was just returning a raw array instead of an object with a root element. That is, instead of this:

{pages : [...]}

I was accidentally returning this:

[...]

Kind of hard to say without a JSBin to look at.