I want to create a route where I'm able to reply to comments (.../comments/:_id/reply), but I'm having problems in publishing the post related with the comment.
Here is the code:
Publications
Meteor.publish('commentUser', function(commentId) {
var comment = Comments.findOne(commentId);
return Meteor.users.find({_id: comment && comment.userId});
});
Meteor.publish('commentPost', function(commentId) {
var comment = Comments.findOne(commentId);
return Posts.find({_id: comment && comment.postId});
});
Meteor.publish('singleComment', function(commentId) {
return Comments.find(commentId);
});
Route
this.route('comment_reply', {
path: '/comments/:_id/reply',
waitOn: function() {
return [
Meteor.subscribe('singleComment', this.params._id),
Meteor.subscribe('commentUser', this.params._id),
Meteor.subscribe('commentPost', this.params._id)
]
},
data: function() {
return {
comment: Comments.findOne(this.params._id)
}
}
});
Comment Reply Template
<template name="comment_reply">
<div class="small-12 columns">
{{# with post}}
{{> postItem}}
{{/with}}
</div>
<div class="small-12 columns">
{{#with comment}}
{{> comment}}
{{/with}}
</div>
{{> commentReplySubmit}}
</template>
Comment Reply Helper
Template.comment_reply.helpers({
postItem: function() {
return Posts.findOne(this.comment.postId);
}
});
When I access that route, the {{#with comment}} renders properly but the {{#with post}} doesn't appears. And if I try to render only {{> postItem}} without {{#with post}} it renders the html, but without the data.
The console prints this alert: You called Route.prototype.resolve with a missing parameter. "_id" not found in params
Thanks in advance!