【问题标题】:Merit not adding points to user action优点不为用户操作添加积分
【发布时间】:2019-01-28 19:10:42
【问题描述】:

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

我正在使用设计。

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)

【问题讨论】:

  • 嗨! FavoriteCoffeeshop belong_to :user?你看到这个维基页面了吗? github.com/merit-gem/merit/wiki/… 用于/users 端点?
  • 你好。我刚刚添加了模型。是的。
  • favorite_coffeeshops#create 现在可以工作了吗?您是否按照 wiki 的说明覆盖了 Devise 控制器?
  • 感谢@TuteC 由于 wiki 仅引用了徽章并没有提及积分,我还没有覆盖设计控制器。这也可以让积分起作用吗?
  • 好的,在创建新的控制器后,我已经开始工作了。 score 20, on: 'coffeeshops#favorite' 完成这项工作。我在确认 Devise 用户更新他们的个人资料时遇到问题。 score 10, on: 'users/confirmations#update', to: :user 还没有完成这项工作。

标签: ruby-on-rails merit-gem


【解决方案1】:

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

rails s

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-25
    • 2015-02-19
    • 2019-01-17
    • 1970-01-01
    • 1970-01-01
    • 2021-06-21
    • 2015-06-23
    相关资源
    最近更新 更多