Module: Refile::ActiveRecord::Attachment

Includes:
Refile::Attachment
Defined in:
lib/refile/attachment/active_record.rb

Constant Summary

Constants included from Refile::Attachment

Refile::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/refile/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