[英]Rails Ruby merit gem observer is not working
我在我的rails项目中使用merit gem并且优点观察者根本不工作。 我的app / observers /文件夹中有Reputation_change_observer.rb
#reputation_change_observer.rb
class ReputationChangeObserver
observe :user
def update(changed_data)
description = changed_data[:description]
# If user is your meritable model, you can query for it doing:
user = User.where(sash_id: changed_data[:sash_id]).first
user.update_life_time_point
user.give_badges
# When did it happened:
datetime = changed_data[:granted_at]
end
end
当声誉改变时,我正在更新用户的生命时间点。 如果用户点达到某一点,则给出徽章。 但这两个功能都不起作用。 任何人有任何想法? 会是什么问题?
在app / observers / reputation_observer.rb中
class ReputationObserver < ActiveRecord::Observer
def after_update(reputation)
# use reputation.previous_changes to get the last changes in reputation object and accordingly write your logic
end
end
在config / application.rb中(激活Reputation_observer)
config.active_record.observers = :reputation_observer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.