From 9ce0af33704eb849e2f5006f7aef686e7d3f973a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 18:06:25 +0800 Subject: [PATCH] fix bug --- app/controllers/zips_controller.rb | 4 +++- app/services/exercise_user_pdf_service.rb | 3 ++- app/services/export_exercises_service.rb | 5 +++-- app/templates/exercise_export/exercise_user.html.erb | 11 ++++++----- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 4de85ec64..c1ff95abd 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -17,7 +17,7 @@ class ZipsController < ApplicationController end def export_exercises - exercises = ExportExercisesService.new(@exercise,@ex_users) + exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) file_name = filename_for_content_disposition(exercises.filename) send_file exercises.ex_zip, filename: file_name, type: 'application/zip' @@ -41,6 +41,8 @@ class ZipsController < ApplicationController ActiveRecord::Base.transaction do 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,"试卷不存在") diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 22804092e..913d0cfbc 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -5,9 +5,10 @@ class ExerciseUserPdfService attr_reader :exercise, :ex_user - def initialize(exercise, ex_user) + def initialize(exercise, ex_user,request_url) @exercise = exercise @ex_user = ex_user + @request_url = request_url @ex_user_user = @ex_user.user @course = @exercise.course end diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index 12b5501f9..48bfc9519 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -3,9 +3,10 @@ class ExportExercisesService include StudentWorksHelper attr_reader :exercise, :ex_users - def initialize(exercise, ex_users) + def initialize(exercise, ex_users,request_url) @exercise = exercise @ex_users = ex_users + @request_url = request_url end def filename @@ -18,7 +19,7 @@ class ExportExercisesService pdfs = [] Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| ex_users.each do |ex_user| - export = ExerciseUserPdfService.new(exercise, ex_user) + export = ExerciseUserPdfService.new(exercise, ex_user,@request_url) pdf = export.ex_pdf pdfs << pdf begin diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 0c1c1bbab..269237520 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -168,15 +168,16 @@ <% end %>
+ <% q_title = q.question_title&.gsub("src='","src='/#{@request_url}") %> + <% if q_type == 5 %> - <%= q.shixun_name&.html_safe %> + <% q_name = q.shixun_name&.gsub("src='","src='/#{@request_url}") %> + <%= q_name&.html_safe %>
- <%= q.question_title&.html_safe %> + <%= q_title&.html_safe %>
- <% elsif q_type == 4 %> - <%= q.question_title&.html_safe %> <% else %> - <%= q.question_title&.html_safe %> + <%= q_title&.html_safe %> <% end %>