Module: Defile::ActiveRecord::Attachment

Includes:
Defile::Attachment
Defined in:
lib/defile/attachment/active_record.rb

Constant Summary

Constants included from Defile::Attachment

Defile::Attachment::IMAGE_TYPES

Instance Method Summary collapse

Instance Method Details

#attachment(name, cache: :cache, store: :store, raise_errors: false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/defile/attachment/active_record.rb', line 6

def attachment(name, cache: :cache, store: :store, raise_errors: false)
  super

  attachment = "#{name}_attachment"

  validate do
    errors = send(attachment).errors
    self.errors.add(name, *errors) unless errors.empty?
  end

  before_save do
    send(attachment).store!
  end
end