我已经安装了Merit,并设置了一些points_rules。当他们创建comment
时,我已经成功地将点添加到我的“用户”中,但其他人都没有。
我正在使用Devise。
point_rules
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
user.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)
答案 0 :(得分:0)
您是否在规则设置后重新启动服务器?可能那是基本原因。我曾经遇到过同样的问题,并以这种方式解决了。
rails s