tabletop-companion/app/models/concerns/deletable_attachments.rb

26 lines
530 B
Ruby
Raw Normal View History

2024-06-04 13:20:57 +00:00
# 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