Module: Paperclip::Helpers

Defined in:
lib/mongoid-paperclip.rb

Instance Method Summary collapse

Instance Method Details

#each_instance_with_attachment(klass, name) ⇒ Object

Find all instances of the given Active Record model klass with attachment name. This method is used by the refresh rake tasks.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mongoid-paperclip.rb', line 29

def each_instance_with_attachment(klass, name)
  if defined?(Mongoid::Document) && class_for(klass) < Mongoid::Document
    class_for(klass).unscoped.where("#{name}_file_name" => {:$exists => true}).to_a.map do |instance|
      yield(instance)
    end
  else
    class_for(klass).unscoped.where("#{name}_file_name IS NOT NULL").find_each do |instance|
      yield(instance)
    end
  end
end