Module: KonoUtils::Concerns::ActiveStorageRemoverHelper::ClassMethods
- Defined in:
- lib/kono_utils/concerns/active_storage_remover_helper.rb
Overview
included do
end
Instance Method Summary collapse
-
#attribute_purger_name(field) ⇒ Symbol
Nome dell’attributo da generare.
-
#has_one_attached_remover(field_name) ⇒ Object
Costruisce i metodi e attributi necessari al modello per gestire la rimozione attraverso l’interfaccia del file allegato.
Instance Method Details
#attribute_purger_name(field) ⇒ Symbol
Nome dell’attributo da generare
55 56 57 |
# File 'lib/kono_utils/concerns/active_storage_remover_helper.rb', line 55 def attribute_purger_name(field) "kono_utils_purge_#{field}".to_sym end |
#has_one_attached_remover(field_name) ⇒ Object
Costruisce i metodi e attributi necessari al modello per gestire la rimozione attraverso l’interfaccia del file allegato
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/kono_utils/concerns/active_storage_remover_helper.rb', line 35 def has_one_attached_remover(field_name) attr = attribute_purger_name(field_name) callback = "make_#{attr}".to_sym attr_accessor attr after_save callback, if: attr define_method(callback) do if self.send(field_name.to_sym).attached? self.send(field_name.to_sym).purge_later end end end |