answer inserts
This commit is contained in:
parent
71786f3c6e
commit
c9375937fa
@ -25,6 +25,8 @@ Style/ExtraSpacing:
|
|||||||
|
|
||||||
Style/IndentationConsistency:
|
Style/IndentationConsistency:
|
||||||
EnforcedStyle: rails
|
EnforcedStyle: rails
|
||||||
|
Exclude:
|
||||||
|
- config/routes.rb
|
||||||
|
|
||||||
Style/MethodDefParentheses:
|
Style/MethodDefParentheses:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
@ -39,6 +41,7 @@ Style/StringLiterals:
|
|||||||
Metrics/AbcSize:
|
Metrics/AbcSize:
|
||||||
Exclude:
|
Exclude:
|
||||||
- db/migrate/**/*
|
- db/migrate/**/*
|
||||||
|
Max: 27
|
||||||
|
|
||||||
Metrics/LineLength:
|
Metrics/LineLength:
|
||||||
Max: 110
|
Max: 110
|
||||||
@ -51,3 +54,4 @@ Metrics/LineLength:
|
|||||||
Metrics/MethodLength:
|
Metrics/MethodLength:
|
||||||
Exclude:
|
Exclude:
|
||||||
- db/migrate/*
|
- db/migrate/*
|
||||||
|
- app/controllers/*
|
||||||
|
@ -9,12 +9,25 @@ class CandidateController < ApplicationController
|
|||||||
redirect_to :summary and return if qid.nil?
|
redirect_to :summary and return if qid.nil?
|
||||||
|
|
||||||
@question = current_candidate.fetch_question(qid)
|
@question = current_candidate.fetch_question(qid)
|
||||||
|
@answer = Answer.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_question
|
def update_answer
|
||||||
redirect_to :summary and return if params.key?(:update)
|
answer_ids = { question_id: answer_params[:question_id], candidate_id: current_candidate.to_i }
|
||||||
redirect_to :saved and return if params.key?(:save)
|
@answer = Answer.find_or_create_by!(answer_ids)
|
||||||
redirect_to :question
|
@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
|
end
|
||||||
|
|
||||||
def summary
|
def summary
|
||||||
@ -56,7 +69,18 @@ class CandidateController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def question_params
|
def answer_params
|
||||||
params.permit(:save)
|
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
|
||||||
end
|
end
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
<%
|
<%
|
||||||
question.input_options.each do | option |
|
question.input_options.each_with_index do | option, i |
|
||||||
option_id = "#{option.parameterize}_#{question.to_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">
|
<div class="form-group-multiples">
|
||||||
<input type="checkbox" class="checkbox"
|
<%= form.check_box(:answer, checkbox_html, option, '') %>
|
||||||
name="input_checkbox_<%= question.to_i %>[]"
|
<%= form.label(option_id, option) %>
|
||||||
id="check_<%= option_id %>"
|
|
||||||
value="<%= option %>"
|
|
||||||
<%= "checked=\"checked\"" if Array(question.answer).include?(option) %>
|
|
||||||
>
|
|
||||||
<label for="check_<%= option_id %>"><%= option %></label>
|
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
-- MOVE TO FLASH HASH --
|
<% if flash[:error].try(:include?, question.to_i) %>
|
||||||
<div class="error">Please select or enter an answer.</div>
|
<div class="error">Please select an answer.</div>
|
||||||
|
<% end %>
|
||||||
|
@ -1,17 +1,14 @@
|
|||||||
<%
|
<%
|
||||||
question.input_options.each do | option |
|
question.input_options.each do | option |
|
||||||
option_id = "#{option.parameterize}_#{question.to_i}"
|
option_id = "#{option.parameterize}_#{question.to_i}"
|
||||||
|
radio_html = {class: 'radio', id: option_id}
|
||||||
%>
|
%>
|
||||||
<div class="form-group-multiples">
|
<div class="form-group-multiples">
|
||||||
<input type="radio" class="radio"
|
<%= radio_button_tag('answer[radio]', option, (question.answer == option), radio_html) %>
|
||||||
name="input_radio_<%= question.to_i %>"
|
<%= label_tag(option_id, option) %>
|
||||||
id="radio_<%= option_id %>"
|
|
||||||
value="<%= option %>"
|
|
||||||
<%= "checked=\"checked\"" if question.answer == option %>
|
|
||||||
>
|
|
||||||
<label for="radio_<%= option_id %>"><%= option %></label>
|
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
-- MOVE TO FLASH HASH --
|
<% 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>
|
<div class="error">Please select an answer.</div>
|
||||||
|
<% end %>
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
<label for="textArea">Enter answer here</label>
|
<label for="answer_text">Enter answer here</label>
|
||||||
<textarea id="textArea" name="textarea" rows="10"><%= question.answer %></textarea>
|
<textarea id="answer_text" name="answer[text]" rows="10"><%= question.answer %></textarea>
|
||||||
|
|
||||||
<div class="chars">Characters remaining: <span></span></div>
|
<div class="chars">Characters remaining: <span></span></div>
|
||||||
|
|
||||||
-- MOVE TO FLASH HASH --
|
<% 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>
|
<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>
|
<textarea data-id="code-js" name="code-js" class="code-answer code-js"><%= @answer['js'] unless @answer.nil? %></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
-- MOVE TO FLASH HASH --
|
<% if flash[:error].try(:include?, @question.to_i) %>
|
||||||
<div class="error">You must write code in one of the above textareas to progress.</div>
|
<div class="error">You must write code in one of the above textareas to progress.</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div class="results" data-id="results"></div>
|
<div class="results" data-id="results"></div>
|
||||||
|
@ -5,12 +5,14 @@
|
|||||||
content_for :footer_title, "Skills Assessment"
|
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">
|
<main class="questions_tpl">
|
||||||
<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} %>
|
<%= 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>
|
</div>
|
||||||
|
|
||||||
<% if @status.on_summary %>
|
<% 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.
|
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 %>
|
<% @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 %>">
|
<article class="answer-sec <%= question.input_type %>-type" data-qid="<%= question.question_id %>">
|
||||||
<div class="question-heading">
|
<div class="question-heading">
|
||||||
<div class="question-title">
|
<div class="question-title">
|
||||||
@ -21,20 +21,21 @@
|
|||||||
|
|
||||||
<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} %>
|
<%= hidden_field_tag 'answer[question_id]', question.question_id %>
|
||||||
|
<%= render partial: question.input_type, locals: {question: question, form: form} %>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
<% end #questions loop %>
|
<% 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 %>
|
<% 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>
|
</main>
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
get "/welcome", to: "candidate#welcome", as: :welcome
|
post "/validate", to: "candidate#validate", as: :validate_candidate
|
||||||
get "/thankyou", to: "candidate#thankyou", as: :thankyou
|
get "/welcome", to: "candidate#welcome", as: :welcome
|
||||||
get "/saved", to: "candidate#saved", as: :saved
|
get "/thankyou", to: "candidate#thankyou", as: :thankyou
|
||||||
get "/summary", to: "candidate#summary", as: :summary
|
get "/saved", to: "candidate#saved", as: :saved
|
||||||
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
|
|
||||||
|
|
||||||
# live coder partial
|
post "/question(/:answer_id)", to: "candidate#update_answer", as: :post_answer
|
||||||
get "/live-coder-entry/:question_id", to: "candidate#live_coder"
|
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"
|
root to: "candidate#welcome"
|
||||||
|
|
||||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||||
end
|
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:
|
dawn7:
|
||||||
candidate: dawn
|
candidate: dawn
|
||||||
question: fed7
|
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
|
saved: 0
|
||||||
submitted: true
|
submitted: true
|
||||||
created_at: <%= DateTime.now() - 38.hours - 34.minutes %>
|
created_at: <%= DateTime.now() - 38.hours - 34.minutes %>
|
||||||
@ -165,7 +165,7 @@ richard6:
|
|||||||
richard7:
|
richard7:
|
||||||
candidate: richard
|
candidate: richard
|
||||||
question: fed7
|
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
|
saved: 0
|
||||||
submitted: true
|
submitted: true
|
||||||
created_at: <%= DateTime.now() - 36.hours - 34.minutes %>
|
created_at: <%= DateTime.now() - 36.hours - 34.minutes %>
|
||||||
|
Loading…
Reference in New Issue
Block a user