I want to add an Observer for Issues to an existing rails application.
I created a plugin, and under plugin's app/model
i saved the custom_observer.rb
It works when I add :custom_observer
to config.active_record.observers
in config/application.rb
I tried something like
RedmineApp::Application.configure do
config.after_initialize do
config.active_record.observers << :custom_observer
end
end
in the plugin's init.rb but that doesn't work.
What is a better way to do that? thanks
If you're using Rails 4.0, observers have been extracted out of the core into a gem called rails-observers
Although you've not said which version of rails you're using, if you're using rails 4, I'd recommend doing this:
GemFile
#Rails Observers
gem "rails-observers", "~> 0.1.2"
Config
#config/application.rb
#Observer Classes
config.active_record.observers = :custom_observer
Observer
#models/customer_observer.rb
class CustomObserver < ActiveRecord::Observer
end
Works for us, and I've supplied live code for you :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With