dev_forum
SylorHuang 6 years ago
parent 15668d4198
commit 9ce0af3370

@ -17,7 +17,7 @@ class ZipsController < ApplicationController
end end
def export_exercises 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) file_name = filename_for_content_disposition(exercises.filename)
send_file exercises.ex_zip, filename: file_name, type: 'application/zip' send_file exercises.ex_zip, filename: file_name, type: 'application/zip'
@ -41,6 +41,8 @@ class ZipsController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
@exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) @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] group_id = params[:exercise_group_id]
if @exercise.blank? if @exercise.blank?
normal_status(-1,"试卷不存在") normal_status(-1,"试卷不存在")

@ -5,9 +5,10 @@ class ExerciseUserPdfService
attr_reader :exercise, :ex_user attr_reader :exercise, :ex_user
def initialize(exercise, ex_user) def initialize(exercise, ex_user,request_url)
@exercise = exercise @exercise = exercise
@ex_user = ex_user @ex_user = ex_user
@request_url = request_url
@ex_user_user = @ex_user.user @ex_user_user = @ex_user.user
@course = @exercise.course @course = @exercise.course
end end

@ -3,9 +3,10 @@ class ExportExercisesService
include StudentWorksHelper include StudentWorksHelper
attr_reader :exercise, :ex_users attr_reader :exercise, :ex_users
def initialize(exercise, ex_users) def initialize(exercise, ex_users,request_url)
@exercise = exercise @exercise = exercise
@ex_users = ex_users @ex_users = ex_users
@request_url = request_url
end end
def filename def filename
@ -18,7 +19,7 @@ class ExportExercisesService
pdfs = [] pdfs = []
Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip|
ex_users.each do |ex_user| ex_users.each do |ex_user|
export = ExerciseUserPdfService.new(exercise, ex_user) export = ExerciseUserPdfService.new(exercise, ex_user,@request_url)
pdf = export.ex_pdf pdf = export.ex_pdf
pdfs << pdf pdfs << pdf
begin begin

@ -168,15 +168,16 @@
<% end %> <% end %>
</div> </div>
<div class="pbt5"> <div class="pbt5">
<% q_title = q.question_title&.gsub("src='","src='/#{@request_url}") %>
<% if q_type == 5 %> <% if q_type == 5 %>
<span class="ques-title"><%= q.shixun_name&.html_safe %></span> <% q_name = q.shixun_name&.gsub("src='","src='/#{@request_url}") %>
<span class="ques-title"><%= q_name&.html_safe %></span>
<div class="mt8 text-gray"> <div class="mt8 text-gray">
<span><%= q.question_title&.html_safe %></span> <span><%= q_title&.html_safe %></span>
</div> </div>
<% elsif q_type == 4 %>
<span class="ques-title"><%= q.question_title&.html_safe %></span>
<% else %> <% else %>
<span class="ques-title"><%= q.question_title&.html_safe %></span> <span class="ques-title"><%= q_title&.html_safe %></span>
<% end %> <% end %>
</div> </div>
</div> </div>

Loading…
Cancel
Save