Created
August 27, 2011 15:18
-
-
Save jygeer/1175499 to your computer and use it in GitHub Desktop.
MongoMapper patch for Paperclip
This file contains hidden or 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
# 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