Using an observer within an Engine
- by Tim
I've created an Engine which is basically used for all of our projects.
Now what I want to do is add a before_create callback to all of the models in this Engine.
After some searching I found out that an observer is the way to go.
So, I've created this observer:
class AuthObserver < ActiveRecord::Observer
def before_create( record )
p record
end
end
And now I need to add it to the application, but of course in my Engine there is no such file as application.rb.
What I tried is adding it to an initializer located in /config/initializers/observers.rb
Like so:
Rails.application.config.active_record.observers = :auth_observer
But this doesn't work, and it throws no errors.
Anybody out here has experience using an observer inside an engine?
Thanks a lot!