testcontroller

This commit is contained in:
yanxd 2014-04-14 21:59:32 +08:00
parent 41f315aac0
commit 31ce41a2d7
2 changed files with 5 additions and 5 deletions

View File

@ -7,7 +7,7 @@ class TestController < ApplicationController
bid.homeworks.each do |homeattach| bid.homeworks.each do |homeattach|
homeattach.attachments.each do |attach| homeattach.attachments.each do |attach|
homeworks_attach_path << attach.diskfile homeworks_attach_path << attach.disk_filename
end end
end end
@paths = homeworks_attach_path @paths = homeworks_attach_path
@ -22,16 +22,16 @@ class TestController < ApplicationController
end end
def ziping files_path def ziping files_path
folder = "/tmp" folder = "#{Rails.root}/files"
input_filename = files_path input_filename = files_path
zipfile_name = "/tmp/archive_#{Time.now.to_i}.zip" zipfile_name = "#{Rails.root}/tmp/archive_#{Time.now.to_i}.zip"
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
input_filename.each do |filename| input_filename.each do |filename|
zipfile.add(filename, folder + '/' + filename) zipfile.add(filename, folder + '/' + filename)
end end
zipfile.get_ouput_stream("ReadMe"){ |os| zipfile.get_ouput_stream("ReadMe"){ |os|
os.write "myFile contains just this" os.write "Homeworks"
} }
end end
zipfile_name zipfile_name

View File

@ -27,7 +27,7 @@
<%= link_to "package", test_zip_path(:homework_id => homework.id)%><br/> <%= link_to "package", test_zip_path(:homework_id => homework.id)%><br/>
<% homework.homeworks.each do |homeattach|%><%#homework.class == Bid %> <% homework.homeworks.each do |homeattach|%><%#homework.class == Bid %>
<% homeattach.attachments.each do |attach|%> <% homeattach.attachments.each do |attach|%>
<%= link_to_attachment attach, author: true %> (<%=attach.author%>) <%= link_to_attachment attach, author: true, :download => true %> (<%=attach.author%>)
<br/> <br/>
<% homeworks_attach_path << attach.storage_path %> <% homeworks_attach_path << attach.storage_path %>
<% end %> <% end %>