目标是在用户的评论获得赞助时为用户提供积分。现在它只是在创建评论时给出分数(5分)并且不会计算upvotes。
我看了this answer并根据它我的代码是正确的。我使用acts_as_votable gem进行upvotes / downvotes。
的Gemfile
gem 'merit', '~> 2.1.1'
comments_controller
def upvote
@comment.liked_by current_user
render "update_likes"
end
point_rules
module Merit
class PointRules
include Merit::PointRulesMethods
def initialize
score 5, :on => ['comments#create'], :to => [:user], category: 'gold_points'
score 2, :on => ['comments#upvote'], :to => [:user], category: 'gold_points'
end
end
end
用户模型
class User < ActiveRecord::Base
has_merit
显示点
<%= @user.points(category: 'gold_points') %>
答案 0 :(得分:0)
我找到了答案:
变化
render "update_likes"
到
render :nothing => true