From 51dc8ae124d3e5eca4921d5f0134782de39bb94e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 19:31:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BApdf=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E5=9B=BE=E7=89=87=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 1 + app/controllers/zips_controller.rb | 5 ++--- app/services/exercise_user_pdf_service.rb | 4 ++-- app/templates/exercise_export/blank_exercise.html.erb | 8 +++++--- app/templates/exercise_export/exercise_user.html.erb | 5 ++--- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 8b65d7c70..2377f411b 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1334,6 +1334,7 @@ class ExercisesController < ApplicationController #导出空白试卷 def export_exercise @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") + @request_url = request.base_url filename = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.current.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 diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index c1ff95abd..b23a3e033 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -42,7 +42,6 @@ class ZipsController < ApplicationController begin @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) @request_url = request.base_url - logger.info("######################____________@request_url____________##########################{@request_url}") group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") @@ -50,12 +49,12 @@ class ZipsController < ApplicationController @course = @exercise.course default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed - @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 + @ex_users = default_ex_users.limit 1 #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 if group_id.present? exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq - @ex_users = @ex_users.where(user_id: user_ids) + @ex_users = @ex_users.where(user_id: user_ids).limit 1 end default_ex_users_size = @ex_users.size diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 913d0cfbc..9b96cd70c 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -38,10 +38,10 @@ class ExerciseUserPdfService kit = PDFKit.new(html) base_css = %w(app/templates/exercise_export/exercise_export.css) base_css.each { |css| kit.stylesheets << Rails.root.join(css) } - #-----正式需删掉 + # #-----正式需删掉 # aa = File.open(Rails.root.join("public/123.html"),"w+") # aa.syswrite(kit.source) - #正式需删掉------- + # #正式需删掉------- file = Tempfile.new(filename) kit.to_pdf(file.path) file diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 2745f8cbe..95a92358f 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -68,13 +68,15 @@ (<%= q&.question_score %>分)
+ <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}") : q.question_title %> <% if q.question_type == 5 %> - <%= q.shixun_name.present? ? q.shixun_name&.html_safe : "" %> + <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}") : q.shixun_name %> + <%= q_name&.html_safe %>
- <%= q.question_title.present? ? q.question_title&.html_safe : "" %> + <%= q_title&.html_safe %>
<% else %> - <%= q.question_title.present? ? q.question_title&.html_safe : "" %> + <%= q_title&.html_safe %> <% end %>
diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index df9c4c6ab..42758af77 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -167,10 +167,9 @@ <% end %>
- <% q_title = q.question_title&.gsub("src='","src='/#{@request_url}") %> - + <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}") : q.question_title %> <% if q_type == 5 %> - <% q_name = q.shixun_name&.gsub("src='","src='/#{@request_url}") %> + <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}") : q.shixun_name %> <%= q_name&.html_safe %>
<%= q_title&.html_safe %>