Module: CarrierWave::MongoidEmbedded::ClassMethods

Defined in:
lib/carrierwave_ext/mongoid_embedded.rb

Instance Method Summary collapse

Instance Method Details

#mount_embedded_uploader(association_name, column) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/carrierwave_ext/mongoid_embedded.rb', line 17

def mount_embedded_uploader association_name, column
  after_save do |doc|
    doc.each_embedded(association_name) do |embedded|
      embedded.send "store_#{column}!"
    end
  end

  before_save do |doc|
    doc.each_embedded(association_name) do |embedded|
      embedded.send "write_#{column}_identifier"
    end
  end

  after_destroy do |doc|
    doc.each_embedded(association_name) do |embedded|
      embedded.send "remove_#{column}!"
    end
  end
end