trying to add “upvoting" to specific courses for Crowducate.me.
As you see from the image, the method is properly called. However, I think the update method (mongo) is not understood. Here’s my personal source code with all commits on Github.
My courses.coffee (mongo collection) // btw: can't format proper indentation here:
class @Course extends Minimongoid
@_collection: new Meteor.Collection('courses')
...
Meteor.methods({
createCourse: ->
userId = Meteor.userId()
throw new Meteor.Error 403, 'Please login to create a course' unless userId
title = 'New Course'
course = Course.create {
owner: userId, courseTitle: title, published: 0, upvoters: [], votes: 0, slug: slugify(title)
}
return course._id
upvote: (courseId) ->
course = Course.first({_id: courseId})
console.log course
#userId = Meteor.user()
Course.update {
_id: courseId,
# upvoters: {$ne: user._id}
# }, {
# $addToSet: {upvoters: user._id}
$inc: {votes: 1}
}
And my html
<template name="courseListItem">
<div class="course-list-item">
<a href="{{#if isMyCoursesPath}}{{pathFor 'courseUpdate'}}{{else}}{{pathFor 'courseShow'}}{{/if}}">
<div class="course-img">
{{#if courseOwner}}
<div class="owner-options">
<a href="{{pathFor 'courseUpdate'}}" class="btn btn-default" title="Edit Course"><i class="fa fa-edit"></i></a>
<button class="btn btn-danger delete" title="Delete Course"><i class="fa fa-trash-o"></i></button>
</div>
{{/if}}
<img class="img-resonsive" src="{{courseThumb}}">
</div>
<div class="well relative">
<div class="course"><h4>{{maxChars courseTitle 40}} by {{owner}}</h4></div>
<p class="course-list-item-preview-text">{{maxChars getText 65}}</p>
<p class="course-list-item-preview-text-votes"><a href="#" class="btn btn-default btn-xs"><i class="upvote fa fa-thumbs-up"></i></a> <strong>{{votes}}</strong> Votes</p>
<!-- <p class="course-list-item-preview-text">12 Votes</p> -->
<div class="bottom">
<p><i class="fa fa-tags" title="Tags"></i> {{maxChars getKeywords 28}}</p>
<p><i class="fa fa-group" title="Age Group"></i> {{age}}</p>
</div>
</div>
</a>
</div>
</template>
My helper:
'click .upvote': (evt) ->
Etc.prevent(evt)
Meteor.call 'upvote', this._id
Maybe this is something specific reg. to Coffeecode or MinimongoId? If you want to run this locally, use mrt install and don’t update to the packages or meteor. Plus, you test the up voting, you need to quickly create a course (under section “teach”).
Best, Amir P.S.: Just to let you know: I’m extending another person’s code and don’t have a lot of experience with CoffeeScript.