我正在尝试使用 merti gem 建立一个带有 rails 的信誉系统,当用户创建超过 8 条评论时我尝试授予徽章但是我每次创建评论时都会收到错误未定义的方法用户。我正在使用设计,但我可以手动创建徽章。有人可以帮忙吗?谢谢 !!
徽章规则
# Be sure to restart your server when you modify this file.
#
# +grant_on+ accepts:
# * Nothing (always grants)
# * A block which evaluates to boolean (recieves the object as parameter)
# * A block with a hash composed of methods to run on the target object with
# expected values (+votes: 5+ for instance).
#
# +grant_on+ can have a +:to+ method name, which called over the target object
module Merit
class BadgeRules
include Merit::BadgeRulesMethods
def initialize
grant_on 'comments#create', badge: 'Jr.Critic', temporary: true, to: :user do |comment|
comment.user.comments.count >= 1 && comment.user.comments.count < 2
end
grant_on 'comments#create', badge: 'Sr.Critic', to: :user do |comment|
comment.user.comments.count >= 3
end
grant_on 'notes#create', badge: 'First story ', to: :user do |note|
note.user.notes.count = 1
end
grant_on 'comments#create', badge: 'Story Teller', to: :user do |comment|
comment.user.comments.count >= 8
end
优点.rb
# Use this hook to configure merit parameters
Merit.setup do |config|
Merit::Badge.create!(
id: 1,
name: "Jr.Critic",
description: "Over 5 comments"
)
Merit::Badge.create!(
id: 2,
name: "Sr.Critic",
description: "Over 50 comments"
)
Merit::Badge.create!(
id: 3,
name: "Story Teller",
description: "Over 5 notes!"
)
Merit::Badge.create!(
id: 4,
name: "First story ",
description: "created first story"
)
Merit::Badge.create!(
id: 5,
name: "commenter ",
description: "created more than 5 comments!"
)
和用户模型
class User < ApplicationRecord
has_merit
end