Fix exception when purge_later is called before save

This commit is contained in:
Paul Chavard 2020-07-08 14:49:50 +02:00
parent a74e52c828
commit ef259c361d

View file

@ -85,6 +85,10 @@ class TypeDeChamp < ApplicationRecord
before_save :remove_drop_down_list, if: -> { type_champ_changed? } before_save :remove_drop_down_list, if: -> { type_champ_changed? }
before_save :remove_repetition, 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) def valid?(context = nil)
super super
if dynamic_type.present? if dynamic_type.present?
@ -293,7 +297,7 @@ class TypeDeChamp < ApplicationRecord
def remove_piece_justificative_template def remove_piece_justificative_template
if !piece_justificative? && piece_justificative_template.attached? if !piece_justificative? && piece_justificative_template.attached?
piece_justificative_template.purge_later @remove_piece_justificative_template = true
end end
end end