diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 2a052fffe..856f808d7 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -355,9 +355,9 @@ module ExercisesHelper exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges) exercise_questions.each do |q| if q.question_type != 5 - answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案 + answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案 else - answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案 + answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案 end if q.question_type <= 2 #为选择题或判断题时 if answers_content.present? #学生有回答时 @@ -369,11 +369,11 @@ module ExercisesHelper standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 if standard_answer.count > 0 - q_score_1 = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + multi_each_score = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 else - q_score_1 = 0.0 + multi_each_score = 0.0 end - answers_content.update_all(:score => q_score_1) + answers_content.update_all(:score => multi_each_score) score1 = score1 + q.question_score end else @@ -424,7 +424,7 @@ module ExercisesHelper end ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 - cha_path = challenge_path exercise_cha.challenge&.path + cha_path = challenge_path(exercise_cha.challenge&.path) game_challenge = game.game_codes.search_challenge_path(cha_path)&.first if game_challenge.present? game_code = game_challenge diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index af883131a..22c10bdb3 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -89,11 +89,12 @@ module ExportHelper if teacher_comments.present? w_18 = "" teacher_comments.each do |t| - user_name = t.user.real_name + user_name = t.user&.real_name user_time = format_time(t.updated_at) - user_score = t.score - user_comment = t.comment - w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") + user_score = t&.score + user_comment = t&.comment + comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" + w_18 = w_18 + comment_title end else w_18 = "--" @@ -160,11 +161,13 @@ module ExportHelper if teacher_comments.present? w_18 = "" teacher_comments.each do |t| - user_name = t.user.real_name + user_name = t.user&.real_name user_time = format_time(t.updated_at) - user_score = t.score - user_comment = t.comment - w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") + user_score = t&.score + user_comment = t&.comment + comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" + # ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") + w_18 = w_18 + comment_title end else w_18 = "--"