You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trustieforge/app/controllers/test_controller.rb

44 lines
1.1 KiB

class TestController < ApplicationController
def zip
homeworks_attach_path = []
homework_id = params[:homework_id]
bid = Bid.find_by_id(homework_id)
bid.homeworks.each do |homeattach|
homeattach.attachments.each do |attach|
homeworks_attach_path << attach.diskfile
end
end
@paths = homeworks_attach_path
zipfile = ziping homeworks_attach_path
send_file zipfile, :filename => bid.name,
:type => detect_content_type(zipfile)
end
def courselist
@courses = Project.course_entities
end
def ziping files_path
folder = "/tmp"
input_filename = files_path
zipfile_name = "/tmp/archive_#{Time.now.to_i}.zip"
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
input_filename.each do |filename|
zipfile.add(filename, folder + '/' + filename)
end
zipfile.get_ouput_stream("ReadMe"){ |os|
os.write "myFile contains just this"
}
end
zipfile_name
end
def detect_content_type(name)
content_type = Redmine::MimeType.of(name)
content_type.to_s
end
end