diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6eaa22f01..c9aeba395 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1294,7 +1294,7 @@ class ExercisesController < ApplicationController def export_exercise @request_url = request.base_url @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") - filename_ = "#{@exercise.user.real_name}_#{@course.name}__#{Time.now.strftime('%Y%m%d_%H%M%S')}" + filename_ = "#{@exercise.user.real_name}_#{@course.name}__#{Time.now.strftime('%Y%m%d_%H%M%S')}.pdf" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" render pdf: 'exercise_export/blank_exercise', filename: filename_, stylesheets: stylesheets end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index dfb6e4237..b799fa40c 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -113,19 +113,26 @@ module ExercisesHelper if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 - if ex.question_type == Exercise::MULTIPLE #多选题 - user_ids.each do |user_id| - answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 - end - end - else #单选题和判断题 - user_ids.each do |user_id| - answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice&.choice_position - if [answer_choice_array] == standard_answer - right_users_count += 1 - end + # if ex.question_type == Exercise::MULTIPLE #多选题 + # user_ids.each do |user_id| + # answer_choice_array = ExerciseChoice.where(id:effictive_users.map{|e| e.exercise_choice_id if a.user_id == user_id}).pluck(:choice_position).uniq + # if answer_choice_array.sort == standard_answer + # right_users_count += 1 + # end + # end + # else #单选题和判断题 + # user_ids.each do |user_id| + # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice&.choice_position + # if [answer_choice_array] == standard_answer + # right_users_count += 1 + # end + # end + # end + + user_ids.each do |user_id| + answer_choice_array = ExerciseChoice.where(id:effictive_users.map{|e| e.exercise_choice_id if a.user_id == user_id}).pluck(:choice_position).uniq + if answer_choice_array.sort == standard_answer + right_users_count += 1 end end