Skip to content

Instantly share code, notes, and snippets.

@guilherme
Created January 24, 2012 20:52
Show Gist options
  • Save guilherme/1672526 to your computer and use it in GitHub Desktop.
Save guilherme/1672526 to your computer and use it in GitHub Desktop.
monkey patch for a more light approach to rake paperclip:refresh
module Paperclip
class << self
def each_instance_with_attachment(klass, name)
unscope_method = class_for(klass).respond_to?(:unscoped) ? :unscoped : :with_exclusive_scope
class_for(klass).send(unscope_method) do
class_for(klass).find_in_batches(:batch_size => 20) do |instance_batches|
instance_batches.each do |instance|
yield(instance) if instance.send(:"#{name}?")
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment