Module: Cdx::AttachmentMacros

Included in:
ApplicationRecord
Defined in:
app/models/concerns/cdx/attachment_macros.rb

Instance Method Summary collapse

Instance Method Details

#has_many_attached(name, class_name) ⇒ Object



9
10
11
12
# File 'app/models/concerns/cdx/attachment_macros.rb', line 9

def has_many_attached(name, class_name)
  has_many name.to_sym, -> { where(name: name) }, class_name: class_name, as: :record, dependent: :destroy
  accepts_nested_attributes_for name.to_sym, allow_destroy: true, reject_if: :all_blank
end

#has_one_attached(name, class_name) ⇒ Object



4
5
6
7
# File 'app/models/concerns/cdx/attachment_macros.rb', line 4

def has_one_attached(name, class_name)
  has_one name.to_sym, -> { where(name: name) }, class_name: class_name, as: :record, dependent: :destroy
  accepts_nested_attributes_for name.to_sym, allow_destroy: true
end