문제

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

도움이 되었습니까?

해결책

I just implemented this gem, https://github.com/chamnap/mongoid-observers/, because I often need it. Please have a look and give me feedback.

다른 팁

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

https://github.com/rails/rails-observers/blob/master/lib/rails/observers/active_model/observing.rb#L19

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top