Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember 1.0.0 RESTAdapter failure

I can't seem to track down the source of this error:

Assertion failed: No model was found for '0'

The JSON is getting fetched by the server, but the app is erroring out before it gets sent to the template. The problem seems to be happening between the REST adapter and the router. The template renders error-free when I use the fixture adapter.

I'm using Ember and Handlebars versions 1.0.0.

Here's my App code:

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

App.ApplicationAdapter = DS.RESTAdapter.extend({
    host: 'http://localhost:3000'
});

App.Router.map(function() {
    this.resource("stories", { path: "/" }, function() {
        this.resource("boards", { path: "/boards"} )
    });
});

App.StoriesRoute = Ember.Route.extend({
    model: function() {
        return this.store.findAll('story');
    }
});

attr = DS.attr;

App.Story = DS.Model.extend({
    color: attr()
});

Handlebars templates

    <script type="text/x-handlebars">
    {{ outlet }}

    </script>

    <script type="text/x-handlebars" data-template-name="stories">
    <ul>
        <li class="storyLine">
            <ul>
                <li id="colorSwatch"></li>
                <li class="board">+</li>
            </ul>
        </li>
    </ul>
    <ul>
    {{#each model}}
        <li class="storyLine">
            <ul>
                <li id="colorSwatch" {{bindAttr class=story.color}}></li>
                <li class="board">dddd</li>
            </ul>
        </li>
    {{/each}}
    </ul>
    </script>

Thanks for your help!

like image 268
buzz mckinnon Avatar asked Sep 05 '13 19:09

buzz mckinnon


1 Answers

The response from the server probably isn't formatted correctly. The JSON needs to have a root that is the same name as your model. See: http://emberjs.com/guides/models/the-rest-adapter/#toc_json-root Your response needs to look something like this:

{
  "story": [
    {
      "id": 0,
      "title": "foo"
    },
    {
      "id": 1,
      "title": "bar"
    }
  ]
}
like image 176
Sean Kent Avatar answered Sep 20 '22 20:09

Sean Kent