live coder load on question template

This commit is contained in:
Derek Montgomery 2016-07-29 11:00:04 -05:00
parent fc6b56d9b8
commit 1a8d7629ff
5 changed files with 32 additions and 24 deletions

View File

@ -113,7 +113,8 @@ $(function(){
});
// If JavaScript is enabled, display the livecoder section dynamically
$("[data-id='live-coder-answer']").load("live-coder-chunk.php .layout", function(){
var qid = 257208768;
$("[data-id='live-coder-answer']").load("/live-coder-entry/" + qid, function(){
// if it loads in, and hide "finish later" checkbox
$("[data-id='live-coder-finish-later']").addClass("hidden");
$('.js-error').addClass('hidden');

View File

@ -35,6 +35,12 @@ class CandidateController < ApplicationController
redirect_to :question
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

View File

@ -14,28 +14,7 @@
</div>
<div data-id="live-coder-answer">
<%
# answers inserted dynamically via jQuery .load()
# to check for JS capability/enabled
<% # answers inserted dynamically via jQuery .load()
# to check for JS capability/enabled
%>
<div class="code-input">
<label for="code-html">HTML</label>
<textarea data-id="code-html" name="code-html"><%= question.answer['html'] unless question.answer.nil? %></textarea>
</div>
<div class="code-input">
<label for="code-css">CSS</label>
<textarea data-id="code-css" name="code-css"><%= question.answer['css'] unless question.answer.nil? %></textarea>
</div>
<div class="code-input">
<label for="code-js">JS</label>
<textarea data-id="code-js" name="code-js"><%= question.answer['js'] unless question.answer.nil? %></textarea>
</div>
-- MOVE TO FLASH HASH --
<div class="error">You must write code in one of the above textareas to progress.</div>
<div class="results" data-id="results"></div>
</div>

View File

@ -0,0 +1,19 @@
<div class="code-input">
<label for="code-html">HTML</label>
<textarea data-id="code-html" name="code-html"><%= @answer['html'] unless @answer.nil? %></textarea>
</div>
<div class="code-input">
<label for="code-css">CSS</label>
<textarea data-id="code-css" name="code-css"><%= @answer['css'] unless @answer.nil? %></textarea>
</div>
<div class="code-input">
<label for="code-js">JS</label>
<textarea data-id="code-js" name="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>
<div class="results" data-id="results"></div>

View File

@ -8,6 +8,9 @@ Rails.application.routes.draw do
get "/question", to: "candidate#question", as: :question
post "/validate", to: "candidate#validate", as: :validate_candidate
# live coder partial
get "/live-coder-entry/:question_id", to: "candidate#live_coder"
root to: "candidate#welcome"
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end