26 lines
530 B
Ruby
26 lines
530 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DeletableAttachments
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
before_save :delete_attachments
|
|
|
|
def delete_attachments
|
|
attachment_reflections.each do |reflection, _|
|
|
if send("delete_#{reflection}")
|
|
send(reflection).purge
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
class_methods do
|
|
def deletable_attachments(*attachments)
|
|
attachments.each do |attachment|
|
|
attribute "delete_#{attachment}", :boolean, default: false
|
|
end
|
|
end
|
|
end
|
|
end
|