Sha256: eabcd3ecd0570ec002a77357d4d892398df387a1fb736e93ffaa20737dfa8e1c
Contents?: true
Size: 773 Bytes
Versions: 6
Compression:
Stored size: 773 Bytes
Contents
module Refile module ActiveRecord module Attachment include Refile::Attachment # Attachment method which hooks into ActiveRecord models # # @see Refile::Attachment#attachment def attachment(name, raise_errors: false, **options) super attacher = "#{name}_attacher" validate do if send(attacher).present? send(attacher).valid? errors = send(attacher).errors self.errors.add(name, *errors) unless errors.empty? end end before_save do send(attacher).store! end after_destroy do send(attacher).delete! end end end end end ::ActiveRecord::Base.extend(Refile::ActiveRecord::Attachment)
Version data entries
6 entries across 6 versions & 1 rubygems