簡體   English   中英

不為用戶行動加分的優點

[英]Merit not adding points to user action

我已經安裝了Merit,並設置了一些points_rules。 當他們創建comment時,我成功地將點添加到我的“用戶”中,但沒有其他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)

設置規則后重新啟動服務器了嗎? 可能那是基本原因。 我曾經遇到過同樣的問題,並以這種方式解決了。

rails s

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM