Skip to content

Instantly share code, notes, and snippets.

@gudata
Created January 5, 2011 20:28
Show Gist options
  • Save gudata/766952 to your computer and use it in GitHub Desktop.
Save gudata/766952 to your computer and use it in GitHub Desktop.
mixing mongoid and activemodel observers
class Buy
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::I18n
include Mongoid::Versioning
extend ActiveModel::Translation
include ActiveModel::Observing
.....
....
end
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
@thegrubbsian
Copy link

So is this actually working for you? Doesn't seem to do it for me.

@gudata
Copy link
Author

gudata commented Feb 23, 2011

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