From 95b5c2ce0c5b946e86e0e44771b566b7f878eef5 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 5 Sep 2017 16:46:51 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E5=8D=95=E9=80=89?= =?UTF-8?q?=E5=A4=9A=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 34 +- app/views/challenges/_choose_type.html.erb | 408 +----------------- .../_single_or_multiple_question.html.erb | 397 +++++++++++++++++ app/views/challenges/_task_edit_page.html.erb | 5 + app/views/challenges/_task_pass_form.html.erb | 60 --- app/views/challenges/edit.html.erb | 2 +- app/views/challenges/edit.js.erb | 1 + 7 files changed, 434 insertions(+), 473 deletions(-) create mode 100644 app/views/challenges/_single_or_multiple_question.html.erb create mode 100644 app/views/challenges/_task_edit_page.html.erb create mode 100644 app/views/challenges/edit.js.erb diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 72ea81bda..834e6b302 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -97,6 +97,10 @@ class ChallengesController < ApplicationController @prev_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos - 1).first if challenge_pos - 1 > 0 @tab = params[:tab].blank? ? 1 : params[:tab].to_i @editor = params[:editor] # 编辑模式 + respond_to do |format| + format.html + format.js + end end def destroy @@ -111,22 +115,22 @@ class ChallengesController < ApplicationController def update ActiveRecord::Base.transaction do @challenge.update_attributes(params[:challenge]) - if (params[:tab] == "1" || params[:tab].nil?) && @challenge.st != 0 - begin - @challenge.challenge_questions.delete_all - params[:question][:cnt].each_with_index do |test, index| - answer = params[:choice][:answer][index] == "0" ? false : true - ChallengeQuestion.create(:option_name => test, :challenge_id => @challenge.id, :position => index, :right_key => answer) - end - redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) - rescue Exception => e - flash[:error] = "#{e.message}" - format.html{redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)} - raise ActiveRecord::Rollback - end - else + #if (params[:tab] == "1" || params[:tab].nil?) && @challenge.st != 0 + # begin + # @challenge.challenge_questions.delete_all + # params[:question][:cnt].each_with_index do |test, index| + # answer = params[:choice][:answer][index] == "0" ? false : true + # ChallengeQuestion.create(:option_name => test, :challenge_id => @challenge.id, :position => index, :right_key => answer) + # end + # redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) + # rescue Exception => e + # flash[:error] = "#{e.message}" + # format.html{redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)} + # raise ActiveRecord::Rollback + # end + #else redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) - end + #end end end diff --git a/app/views/challenges/_choose_type.html.erb b/app/views/challenges/_choose_type.html.erb index a9fc7ec70..35ed85afc 100644 --- a/app/views/challenges/_choose_type.html.erb +++ b/app/views/challenges/_choose_type.html.erb @@ -3,19 +3,16 @@
-
+
+
-
" id="correct_tip"> - 正确 -
-" id="error_tip"> - 错误 -
1.单选题
应在下列程序划线处填入的语句是()
<%= question.option_name %>
<%= question.option_name %>
+ 3/5 +
++ 5/5 全部通过 +
+ <% @game_challenge.challenge_chooses.each_with_index do |choose, index| %> +<%= (index + 1).to_s + "." + (choose.category == 1 ? "单选题" : "多选题") %>
-+ + <% if choose.category == 1 %> + + <% else %> + + + <% end %> + + +
+ <% end %> + +<%= (index + 1).to_s + "." + (choose.category == 1 ? "单选题" : "多选题") %>
-<%= (index + 1).to_s + "." + (choose.category == 1 ? "单选题" : "多选题") %>
+<% if choose.category == 1 %> - + name="answer[<%= index + 1 %>]" category="<%= choose.category %>" value="<%= (question.position + 65).chr %>" id="result_<%= index %>_<%= i %>" class="ml-3 mr5 magic-radio ml5"> <% else %> - + name="answer[]" category="<%= choose.category %>" value="<%= (question.position + 65).chr %>" id="result_<%= index %>_<%= i %>" class="ml-3 mr5 magic-checkbox ml5"> <% end %> - +
<% end %> -