I am using merit gem in my rails project and the merit observer is not working at all. I have reputation_change_observer.rb in my app/observers/ folder
#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
When the reputation changes I am updating the life time point of the user. And gives the badges if the user point reaches certain point. But these two functionalities are not working. Anyone has any idea? what would be the issue?
In 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
In config/application.rb (Activate reputation_observer)
config.active_record.observers = :reputation_observer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With