I have observers set up to award badges on model changes. It works when I'm using the view, but I doesn't seem to fire when I do something like : Photo.create(:user_id => user.id, :file => file) from the console or from the seed file.
Any idea ?
class ExplorerObserver < ActiveRecord::Observer
observe :photo
def after_save(photo)
user = photo.user
Explorer.award_achievements_for(user) unless photo.new_record?
end
end
My mistake, it was a silly issue, but for the archive, here is my answer :
If you have multiple observers, dont put multiple lines like that
config.active_record.observers = :popular_observer
config.active_record.observers = :explorer_observer
instead chain your observers, my previous code was overwriting the observers with the last one !
config.active_record.observers = :popular_observer, :explorer_observer
Did you forget to put it in config/application.rb
, inside your Application
class?
config.active_record.observers = :photo_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