answer inserts
This commit is contained in:
parent
71786f3c6e
commit
c9375937fa
@ -25,6 +25,8 @@ Style/ExtraSpacing:
|
||||
|
||||
Style/IndentationConsistency:
|
||||
EnforcedStyle: rails
|
||||
Exclude:
|
||||
- config/routes.rb
|
||||
|
||||
Style/MethodDefParentheses:
|
||||
Enabled: false
|
||||
@ -39,6 +41,7 @@ Style/StringLiterals:
|
||||
Metrics/AbcSize:
|
||||
Exclude:
|
||||
- db/migrate/**/*
|
||||
Max: 27
|
||||
|
||||
Metrics/LineLength:
|
||||
Max: 110
|
||||
@ -51,3 +54,4 @@ Metrics/LineLength:
|
||||
Metrics/MethodLength:
|
||||
Exclude:
|
||||
- db/migrate/*
|
||||
- app/controllers/*
|
||||
|
@ -9,12 +9,25 @@ class CandidateController < ApplicationController
|
||||
redirect_to :summary and return if qid.nil?
|
||||
|
||||
@question = current_candidate.fetch_question(qid)
|
||||
@answer = Answer.new
|
||||
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
|
||||
def update_answer
|
||||
answer_ids = { question_id: answer_params[:question_id], candidate_id: current_candidate.to_i }
|
||||
@answer = Answer.find_or_create_by!(answer_ids)
|
||||
@answer.answer = answer_for_type
|
||||
@answer.saved = answer_params[:save]
|
||||
@answer.submitted = answer_params[:next]
|
||||
|
||||
if @answer.save
|
||||
redirect_to :summary and return if params.key?(:update)
|
||||
redirect_to :saved and return if params.key?(:save)
|
||||
redirect_to :question
|
||||
else
|
||||
flash[:error] = [answer_params[:question_id]]
|
||||
@question = current_candidate.fetch_question(qid)
|
||||
render :question
|
||||
end
|
||||
end
|
||||
|
||||
def summary
|
||||
@ -56,7 +69,18 @@ class CandidateController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def question_params
|
||||
params.permit(:save)
|
||||
def answer_params
|
||||
params.require(:answer).permit(
|
||||
:question_id, :answer_id,
|
||||
:save, :next, :summary,
|
||||
:radio, :text, checkbox: [], live_coder: []
|
||||
)
|
||||
end
|
||||
|
||||
def answer_for_type
|
||||
return answer_params[:radio] unless answer_params[:radio].nil?
|
||||
return answer_params[:text] unless answer_params[:text].nil?
|
||||
return answer_params[:checkbox] unless answer_params[:checkbox].nil?
|
||||
return answer_params[:live_coder] unless answer_params[:live_coder].nil?
|
||||
end
|
||||
end
|
||||
|
@ -1,17 +1,19 @@
|
||||
<%
|
||||
question.input_options.each do | option |
|
||||
option_id = "#{option.parameterize}_#{question.to_i}"
|
||||
question.input_options.each_with_index do | option, i |
|
||||
option_id = "#{question.question_id}_#{i}"
|
||||
|
||||
checkbox_html = {class: 'checkbox',
|
||||
id: "answer_#{option_id}",
|
||||
name: "answer[checkbox][]",
|
||||
checked: Array(question.answer).include?(option)
|
||||
}
|
||||
%>
|
||||
<div class="form-group-multiples">
|
||||
<input type="checkbox" class="checkbox"
|
||||
name="input_checkbox_<%= question.to_i %>[]"
|
||||
id="check_<%= option_id %>"
|
||||
value="<%= option %>"
|
||||
<%= "checked=\"checked\"" if Array(question.answer).include?(option) %>
|
||||
>
|
||||
<label for="check_<%= option_id %>"><%= option %></label>
|
||||
<%= form.check_box(:answer, checkbox_html, option, '') %>
|
||||
<%= form.label(option_id, option) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
-- MOVE TO FLASH HASH --
|
||||
<div class="error">Please select or enter an answer.</div>
|
||||
<% if flash[:error].try(:include?, question.to_i) %>
|
||||
<div class="error">Please select an answer.</div>
|
||||
<% end %>
|
||||
|
@ -1,17 +1,14 @@
|
||||
<%
|
||||
question.input_options.each do | option |
|
||||
option_id = "#{option.parameterize}_#{question.to_i}"
|
||||
radio_html = {class: 'radio', id: option_id}
|
||||
%>
|
||||
<div class="form-group-multiples">
|
||||
<input type="radio" class="radio"
|
||||
name="input_radio_<%= question.to_i %>"
|
||||
id="radio_<%= option_id %>"
|
||||
value="<%= option %>"
|
||||
<%= "checked=\"checked\"" if question.answer == option %>
|
||||
>
|
||||
<label for="radio_<%= option_id %>"><%= option %></label>
|
||||
<%= radio_button_tag('answer[radio]', option, (question.answer == option), radio_html) %>
|
||||
<%= label_tag(option_id, option) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
-- MOVE TO FLASH HASH --
|
||||
<div class="error">Please select or enter an answer. (The character limit for a textarea answer is 1000)</div>
|
||||
<% if flash[:error].try(:include?, question.to_i) %>
|
||||
<div class="error">Please select an answer.</div>
|
||||
<% end %>
|
||||
|
@ -1,7 +1,8 @@
|
||||
<label for="textArea">Enter answer here</label>
|
||||
<textarea id="textArea" name="textarea" rows="10"><%= question.answer %></textarea>
|
||||
<label for="answer_text">Enter answer here</label>
|
||||
<textarea id="answer_text" name="answer[text]" rows="10"><%= question.answer %></textarea>
|
||||
|
||||
<div class="chars">Characters remaining: <span></span></div>
|
||||
|
||||
-- MOVE TO FLASH HASH --
|
||||
<div class="error">Please select or enter an answer. (The character limit for a textarea answer is 1000)</div>
|
||||
<% if flash[:error].try(:include?, question.to_i) %>
|
||||
<div class="error">Please select or enter an answer. (The character limit for a textarea answer is 1000)</div>
|
||||
<% end %>
|
||||
|
@ -13,7 +13,8 @@
|
||||
<textarea data-id="code-js" name="code-js" class="code-answer code-js"><%= @answer['js'] unless @answer.nil? %></textarea>
|
||||
</div>
|
||||
|
||||
-- MOVE TO FLASH HASH --
|
||||
<div class="error">You must write code in one of the above textareas to progress.</div>
|
||||
<% if flash[:error].try(:include?, @question.to_i) %>
|
||||
<div class="error">You must write code in one of the above textareas to progress.</div>
|
||||
<% end %>
|
||||
|
||||
<div class="results" data-id="results"></div>
|
||||
|
@ -5,12 +5,14 @@
|
||||
content_for :footer_title, "Skills Assessment"
|
||||
%>
|
||||
|
||||
<%= form_tag post_question_path, id: 'answer-form', data: {qid: @question.question_id} do %>
|
||||
<%= form_for(@answer, url: post_answer_path(@answer.id), html:{id: 'answer-form', data: {qid: @question.question_id}}) do |form| %>
|
||||
<main class="questions_tpl">
|
||||
<h2 class="question-text"><%= @question.question %></h2>
|
||||
|
||||
<div class="content-well">
|
||||
<%= render partial: @question.input_type, locals: {question: @question} %>
|
||||
<%= hidden_field_tag 'answer[question_id]', @question.question_id %>
|
||||
<%= hidden_field_tag 'answer[answer_id]', @question.answer_id %>
|
||||
<%= render partial: @question.input_type, locals: {question: @question, form: form} %>
|
||||
</div>
|
||||
|
||||
<% if @status.on_summary %>
|
||||
|
@ -5,8 +5,8 @@
|
||||
Once you're done, hit the button at the bottom of the page to submit your answers.
|
||||
</p>
|
||||
|
||||
<%= form_tag(post_summary_path) do %>
|
||||
<% @quiz.each do |question| %>
|
||||
<% @quiz.each do |question| %>
|
||||
<%= form_for(:answer, url: post_summary_path, html:{id: 'summary-form'}) do |form| %>
|
||||
<article class="answer-sec <%= question.input_type %>-type" data-qid="<%= question.question_id %>">
|
||||
<div class="question-heading">
|
||||
<div class="question-title">
|
||||
@ -21,20 +21,21 @@
|
||||
|
||||
<div class="answer-container">
|
||||
<fieldset disabled class="answer-block">
|
||||
<%= render partial: question.input_type, locals: {question: question} %>
|
||||
<%= hidden_field_tag 'answer[question_id]', question.question_id %>
|
||||
<%= render partial: question.input_type, locals: {question: question, form: form} %>
|
||||
</fieldset>
|
||||
</div>
|
||||
</article>
|
||||
<% end #questions loop %>
|
||||
|
||||
<% if @status.can_submit %>
|
||||
<div class="btn-container-right">
|
||||
<input type="submit" class="submit-button" value="Submit all answers" name="submit" />
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="error">Sorry, you must answer all questions before you can submit.</div>
|
||||
<% end %>
|
||||
|
||||
<% end #form_tag %>
|
||||
|
||||
<% if @status.can_submit %>
|
||||
<div class="btn-container-right">
|
||||
<input type="submit" class="submit-button" value="Submit all answers" name="submit" />
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="error">Sorry, you must answer all questions before you can submit.</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
</main>
|
||||
|
@ -1,16 +1,17 @@
|
||||
Rails.application.routes.draw do
|
||||
get "/welcome", to: "candidate#welcome", as: :welcome
|
||||
get "/thankyou", to: "candidate#thankyou", as: :thankyou
|
||||
get "/saved", to: "candidate#saved", as: :saved
|
||||
get "/summary", to: "candidate#summary", as: :summary
|
||||
post "/summary", to: "candidate#update_summary", as: :post_summary
|
||||
post "/question", to: "candidate#update_question", as: :post_question
|
||||
get "/question", to: "candidate#question", as: :question
|
||||
post "/validate", to: "candidate#validate", as: :validate_candidate
|
||||
post "/validate", to: "candidate#validate", as: :validate_candidate
|
||||
get "/welcome", to: "candidate#welcome", as: :welcome
|
||||
get "/thankyou", to: "candidate#thankyou", as: :thankyou
|
||||
get "/saved", to: "candidate#saved", as: :saved
|
||||
|
||||
# live coder partial
|
||||
get "/live-coder-entry/:question_id", to: "candidate#live_coder"
|
||||
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
|
||||
|
||||
post "/summary", to: "candidate#update_summary", as: :post_summary
|
||||
get "/summary", to: "candidate#summary", as: :summary
|
||||
|
||||
root to: "candidate#welcome"
|
||||
|
||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||
end
|
||||
|
9
db/sql/candidate_quiz.sql
Normal file
9
db/sql/candidate_quiz.sql
Normal file
@ -0,0 +1,9 @@
|
||||
select c.id candidate_id
|
||||
, c.name, c.test_hash
|
||||
, q.quiz_id, q.id question_id, a.id answer_id, q.sort
|
||||
, q.question, q.category, q.input_type, q.input_options, a.answer
|
||||
, ifnull(a.saved, false) saved, ifnull(a.submitted, false) submitted , a.updated_at
|
||||
from candidates c
|
||||
inner join questions q on q.quiz_id = c.quiz_id
|
||||
left join answers a on a.candidate_id = c.id AND a.question_id = q.id
|
||||
order by c.name, q.sort;
|
4
test/fixtures/answers.yml
vendored
4
test/fixtures/answers.yml
vendored
@ -75,7 +75,7 @@ dawn6:
|
||||
dawn7:
|
||||
candidate: dawn
|
||||
question: fed7
|
||||
answer: {html: '<p>This means <strong>jQuery</strong> needs to be available in live-coder!</p>', css: "strong {font-size: 1.6em;}\n .green {color: green;}", js: '$("strong").addClass("green");'}
|
||||
answer: {html: '<p>This means <strong>jQuery</strong> needs to be available in live-coder!</p>', css: "strong {font-size: 1.6em;}\n.green {color: green;}", js: '$("strong").addClass("green");'}
|
||||
saved: 0
|
||||
submitted: true
|
||||
created_at: <%= DateTime.now() - 38.hours - 34.minutes %>
|
||||
@ -165,7 +165,7 @@ richard6:
|
||||
richard7:
|
||||
candidate: richard
|
||||
question: fed7
|
||||
answer: {html: '<p>This means <strong>jQuery</strong> needs to be available in live-coder!</p>', css: "strong {font-size: 1.6em;} .green {color: green;}", js: '$("strong").addClass("green");'}
|
||||
answer: {html: '<p>This means <strong>jQuery</strong> needs to be available in live-coder!</p>', css: "strong {font-size: 1.6em;}\n.green {color: green;}", js: '$("strong").addClass("green");'}
|
||||
saved: 0
|
||||
submitted: true
|
||||
created_at: <%= DateTime.now() - 36.hours - 34.minutes %>
|
||||
|
Loading…
Reference in New Issue
Block a user