- decreases startup time by not loading all your models
- makes it possible to preload config/environment.rb and still test models -> spin/zeus
- makes dependencies obvious
- replaces ActiveRecord magic with ruby
- makes your app Rails 4 ready
# config/environment.rb
config.observers = [:foo_observer]
# app/models/user.rb
class User < ActiveRecord::Base
....
end
# app/observers/foo_observer.rb
class FooObserver < ActiveRecord::Observer
observes :user
def after_save(user)
....
end
end
# app/models/user.rb
class User < ActiveRecord::Base
include FooObserver
end
# app/observers/foo_observer.rb
module FooObserver
class << self
def included(base)
base.after_save{|user| more_descriptive_name(user) }
end
def more_descriptive_name(user)
...
end
end
end