From 5f9a9d059efd53b17050f314504616f73124f981 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 7 Nov 2019 15:11:24 +0000 Subject: [PATCH] dossiers: render JSON if needed When receiving a request that expects JSON, return a simple '200'. This avoids the unecessary work of rendering all the HTML page (which ultimately will not be used). --- app/controllers/users/dossiers_controller.rb | 21 ++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 78039da87..575473a69 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -143,18 +143,19 @@ module Users errors = update_dossier_and_compute_errors - if errors.present? + if passage_en_construction? && errors.blank? + @dossier.en_construction! + NotificationMailer.send_initiated_notification(@dossier).deliver_later + return redirect_to(merci_dossier_path(@dossier)) + elsif errors.present? flash.now.alert = errors - render :brouillon else - if passage_en_construction? - @dossier.en_construction! - NotificationMailer.send_initiated_notification(@dossier).deliver_later - redirect_to merci_dossier_path(@dossier) - else - flash.now.notice = 'Votre brouillon a bien été sauvegardé.' - render :brouillon - end + flash.now.notice = 'Votre brouillon a bien été sauvegardé.' + end + + respond_to do |format| + format.html { render :brouillon } + format.json { head :ok } end end