2016-07-27 22:16:12 -05:00
|
|
|
class CandidateController < ApplicationController
|
|
|
|
def welcome
|
|
|
|
end
|
|
|
|
|
|
|
|
def question
|
2016-07-29 13:34:23 -05:00
|
|
|
@status = QuizStatus.new(current_candidate)
|
|
|
|
qid = @status.current_question_id
|
|
|
|
|
|
|
|
redirect_to :summary and return if qid.nil?
|
|
|
|
|
|
|
|
@question = current_candidate.fetch_question(qid)
|
2016-07-27 22:16:12 -05:00
|
|
|
end
|
|
|
|
|
2016-07-28 08:47:34 -05:00
|
|
|
def update_question
|
2016-07-28 20:54:08 -05:00
|
|
|
redirect_to :summary and return if params.key?(:update)
|
|
|
|
redirect_to :saved and return if params.key?(:save)
|
2016-07-28 08:47:34 -05:00
|
|
|
redirect_to :question
|
|
|
|
end
|
|
|
|
|
2016-07-27 22:16:12 -05:00
|
|
|
def summary
|
2016-07-29 13:34:23 -05:00
|
|
|
@quiz = current_candidate.my_quiz
|
|
|
|
@status = QuizStatus.new(current_candidate)
|
|
|
|
|
|
|
|
redirect_to :question and return unless @status.current_question_id.nil?
|
2016-07-28 20:54:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def update_summary
|
|
|
|
redirect_to :summary
|
2016-07-27 22:16:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def thankyou
|
2016-07-29 11:53:01 -05:00
|
|
|
redirect_to root_path if session[:test_id].nil?
|
|
|
|
reset_session
|
2016-07-27 22:16:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def saved
|
|
|
|
end
|
2016-07-28 08:47:34 -05:00
|
|
|
|
|
|
|
def validate
|
2016-07-29 11:53:01 -05:00
|
|
|
candidate = Candidate.find_by(test_hash: params['test_id'])
|
|
|
|
|
|
|
|
if candidate.nil?
|
|
|
|
reset_session
|
|
|
|
redirect_to root_path, alert: "Sorry, incorrect test id"
|
|
|
|
else
|
|
|
|
session[:test_id] = candidate.test_hash
|
|
|
|
redirect_to :question
|
|
|
|
end
|
2016-07-28 08:47:34 -05:00
|
|
|
end
|
2016-07-28 09:37:46 -05:00
|
|
|
|
2016-07-29 11:00:04 -05:00
|
|
|
def live_coder
|
|
|
|
@question = Question.find(params[:question_id])
|
|
|
|
@answer = @question.answers.order("RAND()").first.answer
|
|
|
|
render layout: false
|
|
|
|
end
|
|
|
|
|
2016-07-29 11:53:01 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def question_params
|
|
|
|
params.permit(:save)
|
|
|
|
end
|
2016-07-27 22:16:12 -05:00
|
|
|
end
|