I’m successfully using ActiveRecord 3.2.9 in a Sinatra 1.3.3 application. I would like to be able to use ActiveRecord::Observer classes, but I’m not sure how to activate them.
The ActiveRecord::Observer docs are specific to Rails about this particular bit:
In order to activate an observer, list it in the config.active_record.observers configuration setting in your config/application.rb file.
Of course, I don’t have a “config” object on which to set this setting. Any ideas?
EDIT
I tried activating the observers like so:
ActiveRecord::Base.observers = [ :thermometer_reading_observer ]
This does something, in that they are correctly set, but they still don’t do anything:
[4] pry(main)> ActiveRecord::Base.observers
=> [:thermometer_reading_observer]
Got it figured out from perusing the ActiveRecord source here:
To activate an observer outside of Rails, do the following (with my Observer as an example):
Hopefully this helps someone!