From bde4e0f4f76a8589bfb0bb5dac7c2496fe3392b4 Mon Sep 17 00:00:00 2001 From: yanxd Date: Tue, 15 Apr 2014 14:33:19 +0800 Subject: [PATCH 1/2] fix courselist --- app/controllers/test_controller.rb | 7 ++++--- lib/tasks/rubyzip.rake | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 lib/tasks/rubyzip.rake diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb index bd591896d..79b2b5641 100644 --- a/app/controllers/test_controller.rb +++ b/app/controllers/test_controller.rb @@ -7,7 +7,8 @@ class TestController < ApplicationController bid.homeworks.each do |homeattach| homeattach.attachments.each do |attach| - homeworks_attach_path << attach.disk_filename + length = attach.storage_path.length + homeworks_attach_path << attach.diskfile.to_s.slice((length+1)..-1) end end @paths = homeworks_attach_path @@ -28,9 +29,9 @@ class TestController < ApplicationController Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| input_filename.each do |filename| - zipfile.add(filename, folder + '/' + filename) + zipfile.add(filename.split('/').last, folder + '/' + filename) end - zipfile.get_ouput_stream("ReadMe"){ |os| + zipfile.get_output_stream("ReadMe"){ |os| os.write "Homeworks" } end diff --git a/lib/tasks/rubyzip.rake b/lib/tasks/rubyzip.rake new file mode 100644 index 000000000..b57d5ed55 --- /dev/null +++ b/lib/tasks/rubyzip.rake @@ -0,0 +1,24 @@ +desc "nyan ruby zip operation" +task :zip do + puts "will building zip tmp files sweeper." +end + +namespace :zip do + desc "ruby zip sweeper" + task :rubyzip_clean do + puts "ruby zip sweeping..." + end +end + +desc "create tmp file, to test" +file 'tmp/test.yml' do + require 'yaml' + var = { + :name => "name", + :age => "age", + :agent => "agent" + } + File.open('tmp/test.yml', 'w') do |f| + f.write YAML.dump({'conf' => var }) + end +end \ No newline at end of file From 3081bff9f44f5b572b2f51d00c812f915950e96e Mon Sep 17 00:00:00 2001 From: yanxd Date: Tue, 15 Apr 2014 14:42:00 +0800 Subject: [PATCH 2/2] test emtry directory --- app/controllers/test_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb index 79b2b5641..1f970b217 100644 --- a/app/controllers/test_controller.rb +++ b/app/controllers/test_controller.rb @@ -25,7 +25,7 @@ class TestController < ApplicationController def ziping files_path folder = "#{Rails.root}/files" input_filename = files_path - zipfile_name = "#{Rails.root}/tmp/archive_#{Time.now.to_i}.zip" + zipfile_name = "#{Rails.root}/tmp/archiveZip/archive_#{Time.now.to_i}.zip" Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| input_filename.each do |filename|