TypeDeChamp: purge notice explicative lors d'un changement de type_champ

This commit is contained in:
benoitqueyron 2024-08-27 17:52:21 +02:00
parent b588b77571
commit 3c5749e45a
No known key found for this signature in database
GPG key ID: AD3C38C9ACA84135

View file

@ -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