Module: CarrierWave::MongoMapper

Includes:
Mount
Defined in:
lib/carrierwave/orm/mongomapper.rb

Instance Method Summary collapse

Methods included from Mount

#uploader_option, #uploader_options, #uploaders

Instance Method Details

#mount_uploader(column, uploader, options = {}, &block) ⇒ Object

See CarrierWave::Mount#mount_uploader for documentation



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/carrierwave/orm/mongomapper.rb', line 10

def mount_uploader(column, uploader, options={}, &block)
  # We need to set the mount_on column (or key in MongoMapper's case)
  # since MongoMapper will attempt to set the filename on 
  # the uploader instead of the file on a Document's initialization.
  options[:mount_on] ||= "#{column}_filename"
  key options[:mount_on]
  
  super
  alias_method :read_uploader, :[]
  alias_method :write_uploader, :[]=
  after_save "store_#{column}!".to_sym
  before_save "write_#{column}_identifier".to_sym
  after_destroy "remove_#{column}!".to_sym
end