Active recording watcher does not shoot console / seed

I have observers created to reward badges from model changes. It works when I use the view, but it doesn’t seem to work when I do something like: Photo.create (: user_id => user.id ,: file => file) from the console or from the sample 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
+5
source share
2 answers

My mistake, it was a stupid problem, but for the archive, here is my answer:

If you have multiple watchers, do not put multiple such strings

config.active_record.observers = :popular_observer
config.active_record.observers = :explorer_observer

instead hook your observers, my previous code was the last to copy the observers!

config.active_record.observers = :popular_observer, :explorer_observer
+3
source

config/application.rb Application?

config.active_record.observers = :photo_observer
+1

All Articles