diff --git a/app/controllers/candidate_controller.rb b/app/controllers/candidate_controller.rb index 051b1ae..0dc39d0 100644 --- a/app/controllers/candidate_controller.rb +++ b/app/controllers/candidate_controller.rb @@ -21,6 +21,11 @@ class CandidateController < ApplicationController @answer = Answer.new end + def update_answer + qid = prep_status.current_question_id + send "process_#{prep_question(qid).input_type}" + end + def live_coder question render layout: false @@ -32,38 +37,6 @@ class CandidateController < ApplicationController redirect_to :question and return unless prep_status.current_question_id.nil? end - def update_text - @answer = prep_answer - @answer.update(answer: answer_params[:text], - saved: answer_params[:save], - submitted: answer_params[:next]) - route_answer - end - - def update_radio - @answer = prep_answer - @answer.update(answer: answer_params[:radio], - saved: answer_params[:save], - submitted: answer_params[:next]) - route_answer - end - - def update_checkbox - @answer = prep_answer - @answer.update(answer: answer_params[:checkbox], - saved: answer_params[:save], - submitted: answer_params[:next]) - route_answer - end - - def update_live_code - @answer = prep_answer - @answer.update(answer: answer_params[:live_code], - saved: answer_params[:save], - submitted: answer_params[:next]) - route_answer - end - # TODO def update_summary # redirect_to :summary @@ -115,4 +88,36 @@ class CandidateController < ApplicationController redirect_to :question end end + + def process_text + @answer = prep_answer + @answer.update(answer: answer_params[:text], + saved: answer_params[:save], + submitted: answer_params[:next]) + route_answer + end + + def process_radio + @answer = prep_answer + @answer.update(answer: answer_params[:radio], + saved: answer_params[:save], + submitted: answer_params[:next]) + route_answer + end + + def process_checkbox + @answer = prep_answer + @answer.update(answer: answer_params[:checkbox], + saved: answer_params[:save], + submitted: answer_params[:next]) + route_answer + end + + def process_live_code + @answer = prep_answer + @answer.update(answer: answer_params[:live_code], + saved: answer_params[:save], + submitted: answer_params[:next]) + route_answer + end end diff --git a/app/views/candidate/live_coder.html.erb b/app/views/candidate/live_coder.html.erb index 4a5c2bb..e78bf2b 100644 --- a/app/views/candidate/live_coder.html.erb +++ b/app/views/candidate/live_coder.html.erb @@ -13,6 +13,6 @@ -<%= render partial: "candidate/answer_errors", locals: {question: question, answer: @answer} %> +<%= render partial: "candidate/answer_errors", locals: {question: @question, answer: @answer} %>
diff --git a/app/views/candidate/question.html.erb b/app/views/candidate/question.html.erb index d0572d8..34eafc1 100644 --- a/app/views/candidate/question.html.erb +++ b/app/views/candidate/question.html.erb @@ -5,7 +5,7 @@ content_for :footer_title, "Skills Assessment" %> -<%= form_for(@answer, url: send("post_#{@question.input_type}_path", @answer.id), html:{id: 'answer-form', data: {qid: @question.question_id}}) do |form| %> +<%= form_for(@answer, url: post_answer_path(@answer.id), html:{id: 'answer-form', data: {qid: @question.question_id}}) do |form| %>