Module: HasManyPurgable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/has_many_purgable.rb
Overview
HasManyPurgable
Mark your model with ‘has_many_purgable’ or ‘has_one_purgable’ (both the same thing) to allow any has_many_attached or has_one_attached to be purgable.
Pass ‘has_many_purgable :files, :avatar’ to only allow the files and avatar to be purged.
Works with effective_bootstrap file_field to display a Delete file on save checkbox to submit a _purge array of attachments to purge.
You must permit the attribute _purge: []
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary collapse
-
#has_many_purgable_names ⇒ Object
All the possible names, merging the actual associations and the given options.
Instance Method Details
#has_many_purgable_names ⇒ Object
All the possible names, merging the actual associations and the given options
54 55 56 57 58 59 60 61 62 |
# File 'app/models/concerns/has_many_purgable.rb', line 54 def has_many_purgable_names names = .fetch(:names) associations = self.class.reflect_on_all_associations .select { |ass| ass.class_name == 'ActiveStorage::Attachment' } .map { |ass| ass.name.to_s.chomp('_attachments').chomp('_attachment').to_sym } names == :all ? associations : (names & associations) end |