skill-assessment-app/app/controllers/candidate_controller.rb
2016-07-29 11:55:53 -05:00

60 lines
1.3 KiB
Ruby

class CandidateController < ApplicationController
def welcome
end
def question
candidate = Candidate.order("RAND()").first
@status = QuizStatus.new(candidate)
@question = candidate.fetch_question(candidate.questions.order("RAND()")[[*0..9].sample].id)
# .where(input_type: 'live-coder')
end
def update_question
redirect_to :summary and return if params.key?(:update)
redirect_to :saved and return if params.key?(:save)
redirect_to :question
end
def summary
@candidate = Candidate.order("RAND()").first # Candidate.where(test_hash: '6NjnourLE6Y').first
@quiz = @candidate.my_quiz
@status = QuizStatus.new(@candidate)
end
def update_summary
redirect_to :summary
end
def thankyou
redirect_to root_path if session[:test_id].nil?
reset_session
end
def saved
end
def validate
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
end
def live_coder
@question = Question.find(params[:question_id])
@answer = @question.answers.order("RAND()").first.answer
render layout: false
end
private
def question_params
params.permit(:save)
end
end