From 1b5aef10f23a3f0598588f9c7e5d573fe6350ec6 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 26 Jan 2021 16:50:32 +0100 Subject: [PATCH] Stop crashing when removed repetition row is submitted --- app/controllers/users/dossiers_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 60d549162..7d17e2b1d 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -346,6 +346,11 @@ module Users if champs_params[:dossier] @dossier.assign_attributes(champs_params[:dossier]) + # FIXME in some cases a removed repetition bloc row is submitted. + # In this case it will be trated as a new records and action will fail. + @dossier.champs.filter(&:repetition?).each do |champ| + champ.champs = champ.champs.filter(&:persisted?) + end if @dossier.champs.any?(&:changed?) @dossier.last_champ_updated_at = Time.zone.now end