Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialjason chan
31,009 PointsHow did posts become post_id? why isn't it posts_id instead?
my supposed json file
var posts = [
{
id: '1',
title: "I love blood",
body: "I awoke in my own bed. If it be that I had not dreamt, the Count must have carried me here. I tried to satisfy myself on the subject, but could not arrive at any unquestionable result. To be sure, there were certain small evidences, such as that my clothes were folded and laid by in a manner which was not my habit. My watch was still unwound, and I am rigorously accustomed to wind it the last thing before going to bed, and many such details. But these things are no proof, for they may have been evidences that my mind was not as usual, and, for some cause or another, I had certainly been much upset. I must watch for proof. Of one thing I am glad. If it was the Count who carried me here and undressed me, he must have been hurried in his task, for my pockets are intact. I am sure this diary would have been a mystery to him which he would not have brooked. He would have taken or distroyed it. As I look around this room, although it has been to me so full of fear, it is now a sort of sanctuary, for nothing can be more dreadful than those aweful women, who were, who are, waiting to suck my blood." },
{
id: '2',
title: "The Count",
body: "I have given the letters. I threw them through the bars of my window with a gold piece, and made what signs I could to have them posted. The man who took them pressed them to his heart and bowed, and then put them in his cap. I could do no more. I stole back to the study, and began to read. As the Count did not come in, I have written here."
},
{
id: '3',
title: "Thievery",
body: "Every scrap of paper was gone, and with it all my notes, my memoranda, relating to railways and travel, my letter of credit, in fact all that might be useful to me were I once outside the castle. I sat and pondered awhile, and then some thought occurred to me, and I made search of my portmanteau and in the wardrobe where I had placed my clothes."
}
];
var comments = [
{
id: '1',
postId: '3',
text: 'What a shame!'
},
{
id: '2',
postId: '3',
text: 'I am so sorry. How are you feeling now?'
},
{
id: '3',
postId: '1',
text: 'I love blodd too!'
},
{
id: '4',
postId: '1',
text: 'Eeew, blood is gross.'
},
{
id: '5',
postId: '2',
text: 'This all sounds so mysterious.'
}
]
posts.js
Blogger.PostRoute = Ember.Route.extend({
model: function(params) {
return posts.findBy('id', params.post_id);
}
});
router.js
Blogger.Router.map(function(){
this.resource('posts', {path: '/'});
this.resource('about', {path: 'about-us'});
this.resource('contact', {path: 'get-in-touch'}, function() {
this.resource('phone');
this.resource('email');
});
this.resource('recent-comments');
this.resource('post', {path: 'posts/:post_id'});
});
This is ember js route question.
2 Answers
Nicolas Sandller
5,643 PointsAre you referring to this line?
return posts.findBy('id', params.post_id);
If this is the case, ember will call the findBy method on the posts data store to match the 'id' property of each post in the array of object posts with whatever id is being read on the url path posts/:post_id. This is why its using "post_id" instead of "posts_id".
Did this help understand?
Nicolas Sandller
5,643 PointsNo worries man :)
jason chan
31,009 Pointsjason chan
31,009 PointsOh nevermind I got it. It's just property of the object from retrieving unique ids. This is database lols. Silly me. Thanks man.