From ef259c361d87b01a5dcedb2a4b5a10baa97b2fed Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 8 Jul 2020 14:49:50 +0200 Subject: [PATCH] Fix exception when purge_later is called before save --- app/models/type_de_champ.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 9896eccfb..27ac435fd 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -85,6 +85,10 @@ class TypeDeChamp < ApplicationRecord before_save :remove_drop_down_list, if: -> { type_champ_changed? } before_save :remove_repetition, 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? @@ -293,7 +297,7 @@ class TypeDeChamp < ApplicationRecord def remove_piece_justificative_template if !piece_justificative? && piece_justificative_template.attached? - piece_justificative_template.purge_later + @remove_piece_justificative_template = true end end