Created
January 5, 2011 20:28
-
-
Save gudata/766952 to your computer and use it in GitHub Desktop.
mixing mongoid and activemodel observers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Buy | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
include Mongoid::I18n | |
include Mongoid::Versioning | |
extend ActiveModel::Translation | |
include ActiveModel::Observing | |
..... | |
.... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OfferObserver < ActiveRecord::Observer | |
observe :sell, :project, :buy | |
# we have to do this manually in Buy - ugly but true | |
def after_save record | |
record.contact.make_contact_client(record, true) | |
record.contact.calc_offers(record) | |
end | |
def after_destroy record | |
record.contact.make_contact_client(record, false) unless record.contact.has_offers_for_user(record.user) | |
record.contact.calc_offers(record) | |
end | |
end |
yes it works for me.
l am with mongoid beta.19 if this would help you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So is this actually working for you? Doesn't seem to do it for me.