Looking at the beginner's tutorial on the EmberJS website, some things got me a little confused.
One instant is that I decided to use ember 1.9.0beta4 with 2.0.0 rudders instead of 1.8.1 / 1.3.0 included in the starter pack.
First, the code included in screencast:
app.js App.Router.map(function() { this.resource('about'); this.resource('posts'); this.resource('post', {path: ':post_id'}) }); App.PostsRoute = Ember.Route.extend({ model: function() { return posts; } });
and
index.html {{#each model}} <tr><td> {{#link-to 'post' this}} {{title}} <small class='muted'>by {{author.name}}</small> {{/link-to}} </td></tr> {{/each}}
This works exactly as expected, and the requested mail appears when clicked.
However, since I'm using 1.9.0, the previous code raises an obsolete warning for {{#each}} , telling me to use {{#each foo in bar}} instead. I understand why this appears and agrees that verbosity helps show exactly what data is looping.
So, I change the line {{#each model}} to {{#each post in model}} and every bit of data disappears ... Then I try to change the code to:
updated index.html {{#each post in model}} <tr><td> {{#link-to 'post' this}} {{post.title}} <small class='muted'>by {{post.author.name}}</small> {{/link-to}} </td></tr> {{/each}}
Excellent! The title and author name reappear for each post. But clicking any of the posts gives me an undefined id . I am changing {{#link-to 'post' this}} to {{#link-to 'post' this.id}} . The same result. I am changing it to {{#link-to 'post' post.id}} . id now enabled, but when I click the link, I get this error:
Error while processing route: post Assertion Failed: You used the dynamic segment post_id in your route post, but App.Post did not exist and you did not override your route `model` hook.
My questions:
What happens inside that forces the post. prefix post. if i just include post in code? For me, I would have to use either this or not need a prefix.
After adding post in to each statement, what happens to this ? Why is it no longer related to the same object?
How can models be called to simplify the classification? post in model should really be post in posts , but I did not find a way to name the data container.
What causes the error now that I no longer treat a model like this ? How can this be fixed?