From b21966c3572d62849d5bd7e179ecb54fb087a81a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 16:05:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=A4=9A=E7=A9=BA=E9=A2=98?= =?UTF-8?q?=E7=9A=84=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_questions_controller.rb | 5 ---- ...611_add_old_exercise_tiankong_choice_id.rb | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 77cc108b3..deb9b3157 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -223,7 +223,6 @@ class ExerciseQuestionsController < ApplicationController end end #试卷未发布时,当标准答案存在时,可修改标准答案内容,可增删标准答案,否则只能修改标准答案,不能增删标准答案 - st_count = 0 @exercise_answers_array = @exercise_question.exercise_standard_answers #问卷的全部标准答案 if standard_answer.present? if @exercise_question.question_type <= 2 #选择题/判断题,标准答案为一个或多个 @@ -232,7 +231,6 @@ class ExerciseQuestionsController < ApplicationController old_left_standard_choices = exercise_standard_choices - common_standard_choices # 以前的差集共同的,剩余的表示需要删掉 new_left_standard_choices = standard_answer - common_standard_choices # 传入的标准答案差集共同的,剩余的表示需要新建 if old_left_standard_choices.count > 0 - st_count += 1 @exercise_answers_array.standard_by_ids(old_left_standard_choices).destroy_all end if new_left_standard_choices.count > 0 #新建标准答案 @@ -258,7 +256,6 @@ class ExerciseQuestionsController < ApplicationController #删除多余的选项 if old_ex_answer_choice_ids.count > new_ex_answer_choice_ids.count #有减少的填空 - st_count += 1 delete_ex_answer_choice_ids = old_ex_answer_choice_ids - new_ex_answer_choice_ids old_ex_answer.standard_by_ids(delete_ex_answer_choice_ids).destroy_all end @@ -284,7 +281,6 @@ class ExerciseQuestionsController < ApplicationController ex_answer_pre[n-1].update(standard_option) end if new_add_choice.count > 0 #表示有新增的 - st_count += 1 new_add_choice.each do |i| standard_option = { :exercise_question_id => @exercise_question.id, @@ -306,7 +302,6 @@ class ExerciseQuestionsController < ApplicationController ex_answer_pre[index].update(standard_option) end if new_delete_choice.count > 0 #表示填空题的答案有删减的 - st_count += 1 new_delete_choice.each do |d| ex_answer_pre[d-1].destroy end diff --git a/db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb b/db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb new file mode 100644 index 000000000..9ad1429e2 --- /dev/null +++ b/db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb @@ -0,0 +1,23 @@ +class AddOldExerciseTiankongChoiceId < ActiveRecord::Migration[5.2] + + def up + #类型为3 的问题答案及标准答案更新exercise_choice_id 为1,即表示第一空 + exercise_question_ids = ExerciseQuestion.where("question_type = 3").pluck(:id) + ExerciseAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: nil).update_all(exercise_choice_id:1) + ExerciseStandardAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: nil).update_all(exercise_choice_id:1) + + exercise_bank_question_ids = ExerciseBankQuestion.where("question_type =3").pluck(:id) + ExerciseBankStandardAnswer.where(exercise_bank_question_id: exercise_bank_question_ids).update_all(exercise_bank_choice_id:1) + end + + def down + #类型为3 的问题答案及标准答案更新exercise_choice_id 为1,即表示第一空 + exercise_question_ids = ExerciseQuestion.where("question_type = 3").pluck(:id) + ExerciseAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: 1).update_all(exercise_choice_id:nil) + ExerciseStandardAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: 1).update_all(exercise_choice_id:nil) + + exercise_bank_question_ids = ExerciseBankQuestion.where("question_type =3").pluck(:id) + ExerciseBankStandardAnswer.where(exercise_bank_question_id: exercise_bank_question_ids).update_all(exercise_bank_choice_id:nil) + end + +end