From 0cc4f8262c80be46fda832924e5cda476b0ba148 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 14:56:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E9=A2=98=E5=BA=93=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 2 +- app/controllers/question_banks_controller.rb | 50 +++++++------------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 3e4dea5e3..2175108fc 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -321,7 +321,7 @@ class ExercisesController < ApplicationController begin check_ids = Exercise.where(id: params[:check_ids]) check_ids.each do |exercise| - current_ex_bank = current_user.exercise_banks.find_by_container(exercise.id,"Exercise").first + current_ex_bank = current_user.exercise_banks.find_by_container(exercise.id,"Exercise")&.first if current_ex_bank.present? #当前用户的选择试卷是否已加入习题库,存在则更新习题库和问题库,否则新建习题库和问题库 ex_params = { :name => exercise.exercise_name, diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 0f9ed4d31..740e3a993 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -182,42 +182,24 @@ class QuestionBanksController < ApplicationController :shixun_id => q.shixun_id } exercise_question = new_exercise.exercise_questions.new option - if exercise_question.save - if q.question_type != 5 - # 复制选择题题目选项 - q.exercise_bank_choices.try(:each_with_index) do |choice, index| - exercise_question.exercise_choices.create({choice_position: index+1, choice_text: choice.choice_text}) - end - # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 - q.exercise_bank_standard_answers.try(:each) do |answer| - exercise_question.exercise_standard_answers.create({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) - end - else - # 复制实训题 - q.exercise_bank_shixun_challenges.try(:each_with_index) do |sc, index| - exercise_question.exercise_shixun_challenges.create({position: index+1, challenge_id: sc.challenge_id, - shixun_id: sc.shixun_id, question_score: sc.question_score}) - end + # question_type:5实训题;其他是非实训题 + if q.question_type != 5 + # 复制选择题题目选项 + q.exercise_bank_choices.try(:each_with_index) do |choice, index| + exercise_question.exercise_choices.new({choice_position: index+1, choice_text: choice.choice_text}) + end + + # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 + q.exercise_bank_standard_answers.try(:each) do |answer| + exercise_question.exercise_standard_answers.new({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) + end + else + # 复制实训题 + q.exercise_bank_shixun_challenges.try(:each_with_index) do |sc, index| + exercise_question.exercise_shixun_challenges.new({position: index+1, challenge_id: sc.challenge_id, + shixun_id: sc.shixun_id, question_score: sc.question_score}) end end - # question_type:5实训题;其他是非实训题git - # if q.question_type != 5 - # # 复制选择题题目选项 - # q.exercise_bank_choices.try(:each_with_index) do |choice, index| - # exercise_question.exercise_choices.new({choice_position: index+1, choice_text: choice.choice_text}) - # end - # - # # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 - # q.exercise_bank_standard_answers.try(:each) do |answer| - # exercise_question.exercise_standard_answers.new({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) - # end - # else - # # 复制实训题 - # q.exercise_bank_shixun_challenges.try(:each_with_index) do |sc, index| - # exercise_question.exercise_shixun_challenges.new({position: index+1, challenge_id: sc.challenge_id, - # shixun_id: sc.shixun_id, question_score: sc.question_score}) - # end - # end end # 添加学生 # if new_exercise.save