From f6fdd64bddc76f02c4284823f50e784c80c3db13 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 15 Sep 2021 14:15:59 +0100 Subject: [PATCH] Save answers as we submit --- app/controllers/case_logs_controller.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 0f7b3c288..68ed9fd08 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -31,14 +31,16 @@ class CaseLogsController < ApplicationController }.freeze def next_question - @subsection = params[:subsection] - @case_log_id = params[:case_log_id] - result = if @subsection - FIRST_QUESTION_FOR_SUBSECTION[@subsection] + subsection = params[:subsection] + @case_log = CaseLog.find(params[:case_log_id]) + result = if subsection + FIRST_QUESTION_FOR_SUBSECTION[subsection] else - @previous_question = params[:previous_question] - NEXT_QUESTION[@previous_question] + previous_question = params[:previous_question] + answer = params[previous_question] + @case_log.update(previous_question => answer) + NEXT_QUESTION[previous_question] end - render result, locals: { case_log_id: @case_log_id } + render result, locals: { case_log_id: @case_log.id } end end