This project is archived and is in readonly mode.
ActiveModel::Observer and ActiveRecord...
-
Yehuda Katz (wycats)
- State changed from new to invalid
- Assigned user set to Yehuda Katz (wycats)
- Milestone cleared.
If you want to use ActiveModel observers outside of ActiveRecord, you will need to include the ActiveModel observer model as such:
class Post include MongoMapper::Document include ActiveModel::Observing def create(*) notify_observers(:before_create, self) value = super notify_observers(after_create, self) value end endIf you wish, you can create a module that you can mix in to any MongoMapper model with observing powers:
module MongoMapper module Observing # This will make sure that ActiveModel::Observing is included onto any model # that MongoMapper::Observing is included onto extend ActiveSupport::Concern include ActiveModel::Observing def create(*) notify_observers(:before_create, self) value = super notify_observers(after_create, self) value end end end class Post include MongoMapper::Document include MongoMapper::Observer endThat said, the MongoMapper folks should probably provide something like this out of the box.
-
Mike (at coverallcrew)
Hi Yehuda,
This still needs ActiveRecord requirements in config/application.rb (when calling config.active_record.observers). Perhaps I'm missing something for Rails to know how to get ActiveModel classes observable.
Cheers.
-
Mike (at coverallcrew)
Can we reopen this to take a look. This still seems like an issue.