While running through the starter tutorial on EmberJS' site, a few things have me a little confused now.
One thing to note immediately is that I decided to use the ember 1.9.0beta4 with handlebars 2.0.0 instead of 1.8.1 / 1.3.0 included in the starter pack.
First the code included in the 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 post appears when clicked.
However, because I'm using 1.9.0, the preceding code produces a deprecated warning for {{#each}}
, telling me to use {{#each foo in bar}}
instead. I understand why this appears and agree the verbosity helps show exactly what data is being looped through.
So I change the line {{#each model}}
to {{#each post in model}}
and every bit of data disappears... I then 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}}
Great! The title and author's name once again appear for each post. But clicking either post gives me an undefined id
. I change {{#link-to 'post' this}}
to {{#link-to 'post' this.id}}
. Same result. I change it to {{#link-to 'post' post.id}}
. The id
is now included 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's `model` hook.
My questions are:
What happens internally that forces the
post.
prefix if I simply include thepost in
code? To me I should be able to use eitherthis
or continue to not need any prefix.After adding
post in
to the each statement, what happens tothis
? Why does it no longer refer to the same object?How can models be named to make it easier to categorize?
post in model
should really bepost in posts
but I haven't found a way to name the data container.What is causing the error now that I'm no longer referring to the model as
this
? How can it be remedied?