updating controllers/views to new quiz access

This commit is contained in:
Mark Moser 2016-07-29 10:53:57 -05:00
parent 80403ad02d
commit fc6b56d9b8
7 changed files with 16 additions and 16 deletions

View File

@ -3,9 +3,10 @@ class CandidateController < ApplicationController
end end
def question def question
@question = Question.order("RAND()").first # .where(input_type: 'live-coder') candidate = Candidate.order("RAND()").first
@status = QuizStatus.new(Candidate.order("RAND()").first) @status = QuizStatus.new(candidate)
@answer = @question.answers.order("RAND()").first @question = candidate.fetch_question(candidate.questions.order("RAND()")[[*0..9].sample].id)
# .where(input_type: 'live-coder')
end end
def update_question def update_question
@ -15,8 +16,8 @@ class CandidateController < ApplicationController
end end
def summary def summary
@candidate = Candidate.where(test_hash: '6NjnourLE6Y').first @candidate = Candidate.order("RAND()").first # Candidate.where(test_hash: '6NjnourLE6Y').first
@answers = @candidate.answers @quiz = @candidate.my_quiz
@status = QuizStatus.new(@candidate) @status = QuizStatus.new(@candidate)
end end

View File

@ -7,7 +7,7 @@
name="input_checkbox_<%= question.to_i %>[]" name="input_checkbox_<%= question.to_i %>[]"
id="check_<%= option_id %>" id="check_<%= option_id %>"
value="<%= option %>" value="<%= option %>"
<%= "checked=\"checked\"" if Array(answer).include?(option) %> <%= "checked=\"checked\"" if Array(question.answer).include?(option) %>
> >
<label for="check_<%= option_id %>"><%= option %></label> <label for="check_<%= option_id %>"><%= option %></label>
</div> </div>

View File

@ -21,17 +21,17 @@
<div class="code-input"> <div class="code-input">
<label for="code-html">HTML</label> <label for="code-html">HTML</label>
<textarea data-id="code-html" name="code-html"><%= answer['html'] unless answer.nil? %></textarea> <textarea data-id="code-html" name="code-html"><%= question.answer['html'] unless question.answer.nil? %></textarea>
</div> </div>
<div class="code-input"> <div class="code-input">
<label for="code-css">CSS</label> <label for="code-css">CSS</label>
<textarea data-id="code-css" name="code-css"><%= answer['css'] unless answer.nil? %></textarea> <textarea data-id="code-css" name="code-css"><%= question.answer['css'] unless question.answer.nil? %></textarea>
</div> </div>
<div class="code-input"> <div class="code-input">
<label for="code-js">JS</label> <label for="code-js">JS</label>
<textarea data-id="code-js" name="code-js"><%= answer['js'] unless answer.nil? %></textarea> <textarea data-id="code-js" name="code-js"><%= question.answer['js'] unless question.answer.nil? %></textarea>
</div> </div>
-- MOVE TO FLASH HASH -- -- MOVE TO FLASH HASH --

View File

@ -7,7 +7,7 @@
name="input_radio_<%= question.to_i %>" name="input_radio_<%= question.to_i %>"
id="radio_<%= option_id %>" id="radio_<%= option_id %>"
value="<%= option %>" value="<%= option %>"
<%= "checked=\"checked\"" if answer == option %> <%= "checked=\"checked\"" if question.answer == option %>
> >
<label for="radio_<%= option_id %>"><%= option %></label> <label for="radio_<%= option_id %>"><%= option %></label>
</div> </div>

View File

@ -1,5 +1,5 @@
<label for="textArea">Enter answer here</label> <label for="textArea">Enter answer here</label>
<textarea id="textArea" name="textarea" rows="10"><%= answer %></textarea> <textarea id="textArea" name="textarea" rows="10"><%= question.answer %></textarea>
<div class="chars">Characters remaining: <span></span></div> <div class="chars">Characters remaining: <span></span></div>

View File

@ -10,7 +10,7 @@
<h2 class="question-text"><%= @question.question %></h2> <h2 class="question-text"><%= @question.question %></h2>
<div class="content-well"> <div class="content-well">
<%= render partial: @question.input_type, locals: {question: @question, answer: @answer.answer } %> <%= render partial: @question.input_type, locals: {question: @question} %>
</div> </div>
<% if @status.on_summary %> <% if @status.on_summary %>

View File

@ -5,16 +5,15 @@
Once you're done, hit the button at the bottom of the page to submit your answers. Once you're done, hit the button at the bottom of the page to submit your answers.
</p> </p>
<%= form_tag(post_summary_path) do %> <%= form_tag(post_summary_path) do %>
<% @candidate.quiz.questions.each do |question| %> <% @quiz.each do |question| %>
<article class="answer-sec"> <article class="answer-sec">
<div class="question-heading"> <div class="question-heading">
<div class="question-title"> <div class="question-title">
<h3><%= question.question %></h3> <h3><%= question.question %></h3>
</div> </div>
<div class="answer-buttons"> <div class="answer-buttons">
<a href="<%= question_path(question.to_i) %>" class="tertiary-btn button-edit" data-questionId="<%= question.to_i %>">Edit</a> <a href="<%= question_path(question.question_id) %>" class="tertiary-btn button-edit" data-questionId="<%= question.question_id %>">Edit</a>
<button class="tertiary-btn button-save">Save</button> <button class="tertiary-btn button-save">Save</button>
<button class="tertiary-btn button-cancel">Cancel</button> <button class="tertiary-btn button-cancel">Cancel</button>
</div> </div>
@ -22,7 +21,7 @@
<div class="answer-container"> <div class="answer-container">
<fieldset disabled class="answer-block"> <fieldset disabled class="answer-block">
<%= render partial: question.input_type, locals: {question: question, answer: @answers.where(question_id: question.id).first.answer } %> <%= render partial: question.input_type, locals: {question: question} %>
</fieldset> </fieldset>
</div> </div>
</article> </article>