diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2fcd7275b..8b65d7c70 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -101,7 +101,7 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 15 @exercises = @exercises.page(@page).per(@limit) - @exercises = @exercises.includes(:exercise_users,:exercise_questions,:exercise_group_settings) + @exercises = @exercises&.includes(:exercise_users,:exercise_questions,:exercise_group_settings) else @exercises = [] end @@ -188,7 +188,7 @@ class ExercisesController < ApplicationController else @is_teacher_or = 0 #为学生 end - @exercise_questions = @exercise.exercise_questions.order("question_number ASC") + @exercise_questions = @exercise.exercise_questions&.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_standard_answers).order("question_number ASC") rescue Exception => e uid_logger_error(e.message) tip_exception("试卷创建失败!") diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 6fbba1c3d..cd9679972 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -90,7 +90,7 @@ class PollsController < ApplicationController @limit = params[:limit] || 15 @polls = @polls.page(@page).per(@limit) - @polls = @polls.includes(:poll_users,:poll_questions,:poll_group_settings) + @polls = @polls&.includes(:poll_users,:poll_questions,:poll_group_settings) else @polls = [] @@ -183,7 +183,7 @@ class PollsController < ApplicationController else @is_teacher_or = 0 end - @poll_questions = @poll.poll_questions.order("question_number ASC") + @poll_questions = @poll.poll_questions&.includes(:poll_answers).order("question_number ASC") rescue Exception => e uid_logger_error(e.message) tip_exception("没有权限") @@ -1148,7 +1148,7 @@ class PollsController < ApplicationController end def get_questions_count - @poll_questions = @poll.poll_questions.order("question_number ASC") + @poll_questions = @poll.poll_questions&.includes(:poll_answers,:poll_votes).order("question_number ASC") @poll_questions_count = @poll_questions.count # 全部的题目数 @poll_question_singles = @poll_questions.ques_count(1).all.count # 单选题 @poll_question_doubles = @poll_questions.ques_count(2).all.count # 多选题