简体   繁体   中英

Gem 'merit' not counting points

The goal is to give a user points when his comment gets an upvote. Now it just gives points when the comment is created(5 points) and doesn't count upvotes.

I've looked at this answer and according to it my code is correct. I'm using acts_as_votable gem for 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

user model

class User < ActiveRecord::Base
  has_merit

display points

<%= @user.points(category: 'gold_points') %>

I found the answer:

change

render "update_likes"

to

render :nothing => true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM