I just implemented this gem, https://github.com/chamnap/mongoid-observers/, because I often need it. Please have a look and give me feedback.
observers for mongoid with rails-observers rails4
-
23-06-2022 - |
質問
I am interested in any solution the title describes.
My gemfile is:
gem "rails", "~> 4.0.0"
gem "mongoid", "~> 3.1.3"
gem 'rails-observers'
I want to use observers on my mongoid models but I receive this error:
https://github.com/mongoid/mongoid/issues/3108
Any ideas are welcome
解決
他のヒント
It looks like you need to include the module in each model and set the observers.
class ORM
include ActiveModel::Observing
end
# Calls PersonObserver.instance
ORM.observers = :person_observer
# Calls Cacher.instance and GarbageCollector.instance
ORM.observers = :cacher, :garbage_collector
# Same as above, just using explicit class references
ORM.observers = Cacher, GarbageCollector
所属していません StackOverflow