On 6-dec-2005, at 1:01, Hunter H. wrote:
One line in the default environment.rb that I was curious about:
Activate observers that should always be running
config.active_record.observers = :cacher, :garbage_collector
This line makes it sound important but it is commented out. Where
learn about what these are and how they function?
Read on ActiveRecord::Observer for the documentation. Moreover,
CacheSweepers are also observers.
Observers are singletons that “watch” your ActiveRecords and fire
when active records are modified (basically, they are standalone
callback containers, so to speak). An observer can be asked to watch
a particular set of models, and a method on the observer is called
for every AR callback.
The configuration is there because the observer needs to be
instantiated explicitly after defining them, as in
or hooked into the controller via the
observers :change_notifier, :html_cleaner line.
Observers are super-cool, for instance if you want to send e-mails
everytime a comment is posted to something etc.
Julian ‘Julik’ Tarkhanov
me at julik.nl