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
56 57 58 |
# File 'lib/kono_utils/concerns/active_storage_remover_helper.rb', line 56 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
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kono_utils/concerns/active_storage_remover_helper.rb', line 34 def has_one_attached_remover(field_name) attr = attribute_purger_name(field_name) callback = "make_#{attr}".to_sym attr_accessor attr after_save callback define_method(callback) do if self.send(attr.to_sym) == '1' if self.send(field_name.to_sym).attached? self.send(field_name.to_sym).purge_later end end end end |