"upvote". TypeError: undefined
" upvoting" Crowducate.me.
, . , , (mongo) . Heres Github.
. coffee ( mongo)//btw: :
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}
}
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>
:
'click .upvote': (evt) ->
Etc.prevent(evt)
Meteor.call 'upvote', this._id
, - . Coffeecode MinimongoId? , mrt install . , , ( "" ).
, P.S.: : Im CoffeeScript.
+3