From 28bebb1ee737610fa46c8d9599ef6b8ef11e6b65 Mon Sep 17 00:00:00 2001 From: yanxd Date: Tue, 15 Apr 2014 21:13:56 +0800 Subject: [PATCH] add Gem zip root path firefox bug --- Gemfile | 3 +++ app/controllers/test_controller.rb | 14 ++++++++++++-- .../redpenny-master/stylesheets/application.css | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index dd19b443..a6d3d4d4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,8 @@ source 'https://rubygems.org' +gem 'rubyzip' +gem 'zip-zip' +gem 'iconv' gem "rails", "3.2.13" gem "jquery-rails", "~> 2.0.2" gem "i18n", "~> 0.6.0" diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb index 2e06fac2..7c212949 100644 --- a/app/controllers/test_controller.rb +++ b/app/controllers/test_controller.rb @@ -15,6 +15,8 @@ class TestController < ApplicationController zipfile = ziping homeworks_attach_path send_file zipfile, :filename => bid.name, :type => detect_content_type(zipfile) + rescue Errno::ENOENT => e + logger.error "[Errno::ENOENT] ===> #{e}" end @@ -23,14 +25,15 @@ class TestController < ApplicationController end def ziping files_path + ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE') folder = "#{Rails.root}/files" input_filename = files_path zipfile_name = "#{Rails.root}/tmp/archiveZip/archive_#{Time.now.to_i}.zip" - Rails.logger.info "================================================================================================================================================================================================================================================================================================================================================================================================#{zipfile_name}" + Dir.mkdir(File.dirname(zipfile_name)) if File.exist?(File.dirname(zipfile_name)) Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| input_filename.each do |filename| - zipfile.add(File.basename(filename), folder + '/' + filename) + zipfile.add(ic.iconv(filename_to_real(File.basename(filename))), folder + '/' + filename) end zipfile.get_output_stream("ReadMe"){ |os| os.write "Homeworks" @@ -43,4 +46,11 @@ class TestController < ApplicationController content_type = Redmine::MimeType.of(name) content_type.to_s end + + def filename_to_real name + attach = Attachment.find_by_disk_filename(name) + attach.filename + end + + end \ No newline at end of file diff --git a/public/themes/redpenny-master/stylesheets/application.css b/public/themes/redpenny-master/stylesheets/application.css index c68e36cd..a7569997 100644 --- a/public/themes/redpenny-master/stylesheets/application.css +++ b/public/themes/redpenny-master/stylesheets/application.css @@ -456,6 +456,7 @@ ul.projects li.root width:auto; float:center; min-height:800px; + border: 1px solid #ffffff; } /*by huang*/