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| %>

<%= @question.question %>

diff --git a/config/routes.rb b/config/routes.rb index 5ff2be6..ba5d123 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,10 +4,7 @@ Rails.application.routes.draw do get "/thankyou", to: "candidate#thankyou", as: :thankyou get "/saved", to: "candidate#saved", as: :saved - post "/question/text(/:answer_id)", to: "candidate#update_text", as: :post_text - post "/question/radio(/:answer_id)", to: "candidate#update_radio", as: :post_radio - post "/question/checkbox(/:answer_id)", to: "candidate#update_checkbox", as: :post_checkbox - post "/question/live-code(/:answer_id)", to: "candidate#update_live_code", as: :post_live_code + post "/question(/:answer_id)", to: "candidate#update_answer", as: :post_answer get "/question(/:question_id)", to: "candidate#question", as: :question get "/live-coder-entry/:question_id", to: "candidate#live_coder", as: :live_coder diff --git a/test/controllers/candidate_controller_test.rb b/test/controllers/candidate_controller_test.rb index 3df9b82..8bc745f 100644 --- a/test/controllers/candidate_controller_test.rb +++ b/test/controllers/candidate_controller_test.rb @@ -53,7 +53,7 @@ class CandidateControllerTest < ActionDispatch::IntegrationTest test "should get flash message on bad radio response" do setup_auth candidates(:martha) qid = questions(:fed1).id - post post_radio_url, params: { answer: { question_id: qid, radio: nil } } + post post_answer_path, params: { answer: { question_id: qid, radio: nil } } assert_response :success assert session[:test_id].present?