You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_controller.rb 1.7 kB

13 years ago
​
13 years ago
12 years ago
​
12 years ago
​
​
​
​
​
​
12 years ago
​
12 years ago
13 years ago
12 years ago
​
​
​
​
12 years ago
​
​
​
​
​
​
​
12 years ago
12 years ago
12 years ago
​
12 years ago
12 years ago
12 years ago
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. class TestController < ApplicationController
  2. helper :UserScore
  3. layout 'bootstrap_base'
  4. def bootstrap; end
  5. def zip
  6. homeworks_attach_path = []
  7. homework_id = params[:homework_id]
  8. bid = Bid.find_by_id(homework_id)
  9. bid.homeworks.each do |homeattach|
  10. homeattach.attachments.each do |attach|
  11. length = attach.storage_path.length
  12. homeworks_attach_path << attach.diskfile.to_s.slice((length+1)..-1)
  13. end
  14. end
  15. @paths = homeworks_attach_path
  16. zipfile = ziping homeworks_attach_path
  17. send_file zipfile, :filename => bid.name,
  18. :type => detect_content_type(zipfile)
  19. rescue Errno::ENOENT => e
  20. logger.error "[Errno::ENOENT] ===> #{e}"
  21. end
  22. def courselist
  23. @courses = Project.course_entities
  24. end
  25. def ziping files_path
  26. ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE')
  27. folder = "#{Rails.root}/files"
  28. input_filename = files_path
  29. zipfile_name = "#{Rails.root}/tmp/archiveZip/archive_#{Time.now.to_i}.zip"
  30. Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
  31. Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
  32. input_filename.each do |filename|
  33. zipfile.add(ic.iconv(filename_to_real(File.basename(filename))), folder + '/' + filename)
  34. end
  35. zipfile.get_output_stream("ReadMe"){ |os|
  36. os.write "Homeworks"
  37. }
  38. end
  39. zipfile_name
  40. end
  41. def detect_content_type(name)
  42. content_type = Redmine::MimeType.of(name)
  43. content_type.to_s
  44. end
  45. def filename_to_real name
  46. attach = Attachment.find_by_disk_filename(name)
  47. attach.filename
  48. end
  49. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...