i have two collections and i want to show reviews only for product thats been clicked , but i am getting all reviews (from reviews collection) no matter what product i click.
Products = new Mongo.Collection("products");
Reviews = new Mongo.Collection("reviews");
for adding and reading reviews i have following code in router.js
// Add new review
this.route('add_review', {
path:'/add_review/:_id',
template:'add_review',
data: function(){
return Products.findOne(this.params._id)
}
});
// Read reviews
this.route('reviews', {
path:'/reviews/:_id',
template:'reviews',
data: function(){
return Products.findOne(this.params._id)
}
});
});
reviews.js
Template.reviews.helpers({
'reviews': function () {
return Reviews.find( )}
})
reviews.html (to read reviews )
<template name="reviews">
<div class="row product-row">
<div class="col-md-2">
<img class="full" src="{{image}}">
</div>
<div class="col-md-10">
<h4>{{name}}</h4>
<p>{{description}}</p>
</div>
</div>
{{#each reviews}}
<p>{{body}} </p>
{{/each}} </template>
You can see the entire code here GitHub repository