fixes #50 - summary page progress on saves

This commit is contained in:
Mark Moser
2016-08-10 10:38:20 -05:00
parent 76bb21a150
commit 2c7948903d
6 changed files with 34 additions and 16 deletions

View File

@ -11,9 +11,10 @@ class QuizController < ApplicationController
def update_answer
@answer = prep_answer answer_params[:question_id]
prep_status
send "process_#{prep_question(answer_params[:question_id]).input_type}"
route_remote and return if request.xhr?
route_answer
route_answer_xhr and return if request.xhr?
route_answer_html
end
def summary
@ -21,11 +22,10 @@ class QuizController < ApplicationController
redirect_to :question and return unless prep_status.current_question_id.nil?
end
def update_summary
prep_status
def submit_summary
not_completed_error = 'You must complete all questions to submit your test.'
record_error = 'There was a problem with your submission. Please try again later.'
redirect_to :summary, flash: { error: not_completed_error } and return unless @status.can_submit
redirect_to :summary, flash: { error: not_completed_error } and return unless prep_status.can_submit
redirect_to :thankyou and return if current_candidate.complete!
redirect_to :summary, flash: { error: record_error }
end
@ -62,9 +62,8 @@ class QuizController < ApplicationController
answer
end
def route_answer
def route_answer_html
if @answer.errors.present?
prep_status
prep_question answer_params[:question_id]
flash[:error] = answer_params[:question_id].to_i
render :question
@ -75,11 +74,16 @@ class QuizController < ApplicationController
end
end
def route_remote
def route_answer_xhr
if @answer.errors.present?
render json: @answer.errors["answer"].to_json, status: 400
else
render json: { message: "Your answer has been updated successfully!" }.to_json
results = {
message: "Your answer has been updated successfully!",
can_submit: prep_status.can_submit,
progress: prep_status.progress
}
render json: results.to_json
end
end