Active Record Observer not firing in console/seed
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
精彩评论