0

我已经安装了 Merit 并设置了一些 points_rules。comment当他们创建一个但没有其他人时,我成功地向我的“用户”添加了积分。

我正在使用设计。

点规则

module Merit
  class PointRules
    include Merit::PointRulesMethods

    def initialize
      score 10, :on => ['user#create', 'user#update'] do |user|
         user.preferred_drink.present?
       end
       score 20, on: 'comments#create', to: :user #is working!
       score 10, on: 'users#update', to: :user
       score 20, on: 'favorite_coffeeshops#create', to: :user  
    end
  end
end

用户.rb

class User < ApplicationRecord
  has_merit
  has_many :favorite_coffeeshops      
  has_many :favorites, through: :favorite_coffeeshops, source: :coffeeshop

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable, :trackable 

favourite_coffeeshop.rb - 加入表。

class FavoriteCoffeeshop < ApplicationRecord
  belongs_to :coffeeshop
  belongs_to :user

用户可以在favorite_coffeeshops表格中添加一个新行,这样就可以正常工作了。

从控制台日志来看,它似乎没有尝试写入绩效模型。

Started PUT "/coffeeshops/new-shop-9c762d25-77e4-499a-b009-1ad150515dbb/favorite?type=favorite" for 127.0.0.1 at 2019-01-13 21:57:08 +0000
Processing by CoffeeshopsController#favorite as HTML
  Parameters: {"authenticity_token"=>"24cQlLc+UYT79P50rrBx9hlXckPj/3nCtVJ7fS6+UKO+UHTGDLBXlwLaVpVLf6Yj46VYyNiH0xdBzaUaU/LbHw==", "type"=>"favorite", "id"=>"new-shop-9c762d25-77e4-499a-b009-1ad150515dbb"}
  Admin Load (0.8ms)  SELECT  "admins".* FROM "admins" WHERE "admins"."id" = $1 ORDER BY "admins"."id" ASC LIMIT $2  [["id", 2], ["LIMIT", 1]]
  Coffeeshop Load (0.5ms)  SELECT  "coffeeshops".* FROM "coffeeshops" WHERE "coffeeshops"."slug" = $1 LIMIT $2  [["slug", "new-shop-9c762d25-77e4-499a-b009-1ad150515dbb"], ["LIMIT", 1]]
  User Load (0.9ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
   (0.3ms)  BEGIN
  FavoriteCoffeeshop Create (0.9ms)  INSERT INTO "favorite_coffeeshops" ("coffeeshop_id", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id"  [["coffeeshop_id", 22], ["user_id", 1], ["created_at", "2019-01-13 21:57:08.172483"], ["updated_at", "2019-01-13 21:57:08.172483"]]
   (0.6ms)  COMMIT
Redirected to http://localhost:3000/coffeeshops/new-shop-9c762d25-77e4-499a-b009-1ad150515dbb
Completed 302 Found in 26ms (ActiveRecord: 7.2ms)
4

1 回答 1

0

您是否在规则设置后重新启动服务器?可能这是基本原因。我遇到了同样的问题并以这种方式解决。

rails s
于 2019-01-28T11:10:42.853 回答