diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 8b65d7c70..3c364b979 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1333,6 +1333,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 = "#{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" diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 4de85ec64..c20546701 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -17,7 +17,8 @@ class ZipsController < ApplicationController end def export_exercises - exercises = ExportExercisesService.new(@exercise,@ex_users) + @request_url = request.base_url + 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' diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6ddbdce0c..fd72b5651 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -335,10 +335,8 @@ module ApplicationHelper end # 导出pdf时,转化markdown为html - def to_markdown(text) + def to_markdown(text,origin_url) return nil if text.blank? - request_url = "http://47.96.87.25:48080" - options = { :autolink => true, :no_intra_emphasis => true, @@ -350,8 +348,7 @@ module ApplicationHelper } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) m_t = markdown.render(text) - m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t - Rails.logger.info("###########__________request_url_________###################{request_url}") + m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{origin_url}") : m_t end end diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index be048c4c2..9b96cd70c 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..0d2d8f3ce 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/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 1dde00e56..153ba1514 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -68,12 +68,12 @@
<% if q.question_type == 5 %> - <%= to_markdown(q.shixun_name) %> + <%= to_markdown(q.shixun_name,@request_url) %>
- <%= to_markdown(q.question_title) %> + <%= to_markdown(q.question_title,@request_url) %>
<% else %> - <%= to_markdown(q.question_title) %> + <%= to_markdown(q.question_title,@request_url) %> <% end %>
@@ -81,14 +81,14 @@ <% q.exercise_choices.each do |s| %>
- <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text,@request_url) %>
<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each do |s| %>
- <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text,@request_url) %>
<% end %> <% elsif q.question_type == 2 %> diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 3e92c5864..bb3723373 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -168,12 +168,12 @@
<% if q.question_type == 5 %> - <%= to_markdown(q.shixun_name) %> + <%= to_markdown(q.shixun_name,@request_url) %>
- <%= to_markdown(q.question_title) %> + <%= to_markdown(q.question_title,@request_url) %>
<% else %> - <%= to_markdown(q.question_title) %> + <%= to_markdown(q.question_title,@request_url) %> <% end %>
@@ -183,7 +183,7 @@ <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %>
- <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text,@request_url) %>
<% end %> <% elsif q_type == 1 %> @@ -195,7 +195,7 @@ <% else %> <% end %> - <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text,@request_url) %> <% end %> <% elsif q_type == 2 %> @@ -335,7 +335,7 @@
- +

<%= ques_user.real_name %><%= ques_comment.first.updated_at.strftime('%Y-%m-%d %H:%M') %>