I have a blog site where going to the url /posts
should list all posts. Then clicking a link for /posts/:post_id
should display the details of that post. However, when clicking the link, it seems that the linkTo
is not passing the :post_id
properly. Here is my code:
Router:
App.Router.map(function() {
this.resource("posts", function() {
this.resource("post", { path: "/:post_id" }, function() {
//other routes
});
});
this.route("posts.index", { path: "/" });//Links root url to posts index template
});
Routes:
/****** Posts ******/
App.PostsRoute = Ember.Route.extend({
});
App.PostsIndexRoute = Ember.Route.extend({
model: function() {
return App.Post.find();
}
});
/****** Post *******/
App.PostRoute = Ember.Route.extend({
});
App.PostIndexRoute = Ember.Route.extend({
});
Controllers:
/****** Posts ******/
App.PostsController = Ember.ArrayController.extend({
});
App.PostsIndexController = Ember.ArrayController.extend({
});
/****** Post ******/
App.PostController = Ember.ObjectController.extend({
});
App.PostIndexController = Ember.ObjectController.extend({
});
Posts/Index Template:
{{#each post in controller}}
<tr>
<td>{{post.name}}</td>
<td>{{post.title}}</td>
<td>{{post.content}}</td>
<td>{{#linkTo post.index post}}View{{/linkTo}}</td>
</tr>
{{/each}}
Every time I click the {{linkTo post.index post}}
, it takes me to the correct url, renders the correct templates (post/index), but nothing displays. I tried putting a model hook in the PostIndexRoute like this:
App.PostIndexRoute = Ember.Route.extend({
model: function(params) {
return App.Post.find(params.post_id);
}
});
But params = {}
It has no data in it. Can someone point me in the right direction? what am I doing wrong?
return this.modelFor("post");
in yourPostIndexRoute
's model hook? – Finn MacCoolthis.modelFor("post")
do? – dmoss18PostIndexRoute
use the model of yourPostRoute
, but apparently, your problem could be solved without that. – Finn MacCool