From 3c5749e45abd101cf724c8e376ddbd62fe5500c9 Mon Sep 17 00:00:00 2001 From: benoitqueyron <72251526+Benoit-MINT@users.noreply.github.com> Date: Tue, 27 Aug 2024 17:52:21 +0200 Subject: [PATCH] TypeDeChamp: purge notice explicative lors d'un changement de type_champ --- app/models/type_de_champ.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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