From 1606e9ddab70950b194a7a5fc2d5c9a535580bcd Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 18 Nov 2015 18:28:17 +0800 Subject: [PATCH 1/2] 0 --- app/controllers/exercise_controller.rb | 4 +++- app/helpers/exercise_helper.rb | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 89a5c195e..f83e31a56 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -136,6 +136,7 @@ class ExerciseController < ApplicationController :question_score => params[:question_score] } @exercise_questions = @exercise.exercise_questions.new option + # params[:question_answer] 题目选项 if params[:question_answer] for i in 1..params[:question_answer].count answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] @@ -154,6 +155,7 @@ class ExerciseController < ApplicationController @exercise_questions.question_number = params[:quest_num].to_i + 1 end if @exercise_questions.save + # params[:exercise_choice] 标准答案参数 standart_answer = ExerciseStandardAnswer.new standart_answer.exercise_question_id = @exercise_questions.id if @exercise_questions.question_type == 1 @@ -161,7 +163,7 @@ class ExerciseController < ApplicationController elsif @exercise_questions.question_type == 2 standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice]) else - standart_answer.answer_text = sigle_selection_standard_answer(params[:exercise_choice]) + standart_answer.answer_text = fill_standart_answer(params[:exercise_choice]) end standart_answer.save respond_to do |format| diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index c1bf07407..3a7c0a00a 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -27,6 +27,10 @@ module ExerciseHelper answer.to_i end + def fill_standart_answer(params) + + end + #判断用户是否已经提交了问卷 def has_commit_exercise?(exercise_id, user_id) pu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id, user_id) From 8cf22767f9d75046fd8a1010771d17b21b53d201 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 18 Nov 2015 19:58:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E9=97=AE=E7=AD=94?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 39 ++++++++++++++++---------- app/helpers/exercise_helper.rb | 7 +++-- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index f363b9297..0afc9dfda 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -156,16 +156,24 @@ class ExerciseController < ApplicationController end if @exercise_questions.save # params[:exercise_choice] 标准答案参数 - standart_answer = ExerciseStandardAnswer.new - standart_answer.exercise_question_id = @exercise_questions.id - if @exercise_questions.question_type == 1 - standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice]) - elsif @exercise_questions.question_type == 2 - standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice]) + # 问答题标准答案有三个,单独处理 + if @exercise_questions.question_type == 3 + for i in 1..params[:exercise_choice].count + standart_answer = ExerciseStandardAnswer.new + standart_answer.exercise_question_id = @exercise_questions.id + standart_answer.answer_text = params[:exercise_choice].values[i-1] + standart_answer.save + end else - standart_answer.answer_text = fill_standart_answer(params[:exercise_choice]) + standart_answer = ExerciseStandardAnswer.new + standart_answer.exercise_question_id = @exercise_questions.id + if @exercise_questions.question_type == 1 + standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice]) + else + standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice]) + end + standart_answer.save end - standart_answer.save respond_to do |format| format.js end @@ -178,16 +186,17 @@ class ExerciseController < ApplicationController # params[:question_answer] eg:A、B、C选项 def update_exercise_question @exercise_question = ExerciseQuestion.find params[:exercise_question] - @exercise_question.question_title = params[:exercise_questions_title].nil? || params[:exercise_questions_title].empty? ? l(:label_enter_single_title) : params[:exercise_questions_title] + @exercise_question.question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title] + @exercise_question.question_score = params[:question_score] ################处理选项 if params[:question_answer] - @exercise_question.exercise_answers.each do |answer| - answer.destroy unless params[:question_answer].keys.include? answer.id.to_s - end + # @exercise_question.exercise_choices.each do |answer| + # answer.destroy unless params[:question_answer].keys.include? answer.id.to_s + # end # 界面需要判断选择题至少有一个选项 - for i in 1..params[:question_answer].count - question = @exercise_question.exercise_answers.find_by_id params[:question_answer].keys[i-1] - answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] + for i in 1..@exercise_question.exercise_choices.count + question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1] + # answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] if question question.exercise_choices_id = i question.answer_text = answer diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index 3a7c0a00a..7f3d1862e 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -27,8 +27,11 @@ module ExerciseHelper answer.to_i end - def fill_standart_answer(params) - + def fill_standart_answer(params, standart_answer) + params.each do |param| + standart_answer.answer_text = param.value + standart_answer.save + end end #判断用户是否已经提交了问卷