diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 6f28c36a1..3204b7cfc 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -210,14 +210,10 @@ class TypeDeChamp < ApplicationRecord before_validation :check_mandatory before_validation :normalize_libelle - before_save :remove_piece_justificative_template, if: -> { type_champ_changed? } + before_save :remove_attachment, if: -> { type_champ_changed? } before_validation :set_drop_down_list_options, if: -> { type_champ_changed? } before_save :remove_block, if: -> { type_champ_changed? } - after_save if: -> { @remove_piece_justificative_template } do - piece_justificative_template.purge_later - end - def valid?(context = nil) super if dynamic_type.present? @@ -767,9 +763,11 @@ class TypeDeChamp < ApplicationRecord end end - def remove_piece_justificative_template + def remove_attachment if !piece_justificative? && piece_justificative_template.attached? - @remove_piece_justificative_template = true + piece_justificative_template.purge_later + elsif !explication? && notice_explicative.attached? + notice_explicative.purge_later end end