"Building an Ember.js Application" video too far out-of-date?


#1

Hi folks - new Ember developer here. I’ve used Tom’s intro blog-building video and app to get started with Ember and it’s been very helpful. The app uses

{{#each model}}

and I noticed the deprecation message on moving from the context-switching form to the keyword form. However, modifying the code to use

{{#each post in posts}}

and referencing

{{post.title}}

in the loop isn’t generating any output. But the demo app also doesn’t define the post or posts models - e.g.

App.Posts = DS.Model.extend()

so I’m wondering if this too is an aspect of the demo video/app that’s out of sync with v1.9.1 ? Poking around, I was able to get the form

{{#each post in model}}

to work, but would like to understand what is necessary to use

{{#each post in posts}}

Thanks.


#2

You could alias model to posts it in your controller:

posts: Ember.computed.alias('model')

#3

Thanks @splattne - Tom’s video demo app didn’t define a posts controller, so creating it and adding your alias definition did allow

{{#each post in posts}}

to work. But this seems like a workaround to fill in for some other piece I must be missing, no? i.e. I wouldn’t expect to need to manually alias ‘posts’ since it is already named as a resource in the router, and the controller itself is named PostsController. Any further thoughts? Thanks.


#4

If this is the code:

It looks like posts is just a global variable as dummy data for this little example app.


#5

I’ve replaced the global ‘posts’ with a JSON api call inside the PostsRoute router, as Tom did in the video.

That said, the real question here has to do with the description of named-parameter {{#each}} helpers described under “MORE CONSISTENT HANDLEBARS SCOPE” found here

The examples suggest that a named model - i.e. ‘posts’ rather than ‘model’ - is standard, so I’m wondering why you would have to explicitly create an alias for “model” inside the controller when “posts” is already named as part of that controller name, as well as the names of the route and the template? I would expect Ember to know the model’s name at the point it is being referenced inside {{#each}} within the ‘posts’ template and the examples at the link above suggest that to me as well. It seems like maybe i’m not understanding something fundamental about the Ember architecture?


#6

I agree that it’d be nice if the video could be updated as it could be confusing for newbies.