Module: CarrierWave::DynaModel

Includes:
Mount
Defined in:
lib/dyna_model/adapters/carrierwave/dyna_model.rb

Instance Method Summary collapse

Instance Method Details

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dyna_model/adapters/carrierwave/dyna_model.rb', line 8

def mount_uploader(column, uploader, options={}, &block)
  options[:mount_on] ||= "#{column}_identifier"
  string_attr options[:mount_on].to_sym

  super

  alias_method :read_uploader, :[]
  alias_method :write_uploader, :[]=
  public :read_uploader
  public :write_uploader

  include CarrierWave::Validations::ActiveModel

  validates_integrity_of  column if uploader_option(column.to_sym, :validate_integrity)
  validates_processing_of column if uploader_option(column.to_sym, :validate_processing)
  
  after_save "store_#{column}!".to_sym
  before_save "write_#{column}_identifier".to_sym
  after_destroy "remove_#{column}!".to_sym

end