Skip to content

Instantly share code, notes, and snippets.

@jygeer
Created August 27, 2011 15:18
Show Gist options
  • Save jygeer/1175499 to your computer and use it in GitHub Desktop.
Save jygeer/1175499 to your computer and use it in GitHub Desktop.
MongoMapper patch for Paperclip
# this fixes a bug in MongoMapper/Paperclip in rails 3.1 https://github.com/jnunemaker/mongomapper/issues/293
# config/initializers/mongo.rb
module MongoMapper
module Plugins
module EmbeddedCallbacks
module InstanceMethods
def run_callbacks(callback, opts = nil, &block)
embedded_docs = []
embedded_associations.each do |association|
embedded_docs += Array(get_proxy(association).send(:load_target))
end
block = embedded_docs.inject(block) do |chain, doc|
if doc.class.respond_to?("_#{callback}_callbacks")
lambda { doc.run_callbacks(callback, &chain) }
else
chain
end
end
super callback, &block
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment