Sha256: 4e1e2dd9b58bd9f6636a4dd1f101ca15ff6cc455d1294c34b736099239c75aa2

Contents?: true

Size: 526 Bytes

Versions: 3

Compression:

Stored size: 526 Bytes

Contents

module Refile
  module ActiveRecord
    module Attachment
      include Refile::Attachment

      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
    end
  end
end

::ActiveRecord::Base.extend(Refile::ActiveRecord::Attachment)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
refile-0.2.4 lib/refile/attachment/active_record.rb
refile-0.2.3 lib/refile/attachment/active_record.rb
refile-0.2.2 lib/refile/attachment/active_record.rb