I have an application that allows users within a group to look at each member's message to the group and lists them out using {{#each comment}}
in my view. I want to limit editing of any comment to only those comments associated with the logged in user using {{#if user.user_id}}
.
I tried to nest an if statement within my each section, but it isn't hiding the edit link for those that don't match this case. Is this due to not having an else statement? Could it be that the nested if is from a different object?
Here is my view:
{{#each comment}}
<div class="col-md-7 col-md-offset-5 comment-card">
<div class="comment-card-header">
<p class="card-date">{{this.commentDateSlug}}</p>
<h3 class="card-title">{{this.title}}</h3>
</div>
<div class="comment-card-body">
<p class="card-report-link">Report: <a href="{{this.commentLink}}" class="card-data-report-url">{{comment.reportLink}}</a></p>
</div>
{{#if user.user_id}}
<p>This is the user: {{user.user_id}}</p>
<div class="annotation-card-footer">
<a href="/app/edit/{{this.commentId}}">Edit</a>
</div>
{{/if}}
</div>
{{/each}}
Here is the route:
appRoutes.route('/')
.get(function(req, res){
models.Comment.findAll({
attributes: ['commentId', 'commentDate', 'dataDateStart', 'dataDateEnd', 'title', 'discovery', 'reportLink'],
order: 'commentDate DESC',
include: [{
model: models.User,
where: { organizationId: req.user.organizationId },
attributes: ['organizationId', 'user_id']
}]
}).then(function(comment){
res.render('pages/app/high-level-activity-feed.hbs',{
comment: comment,
user: req.user
});
})
})
This is the user:{{../user.user_id}}