디렉토리의 모든 파일을 압축하려고 시도 할 때 RubyZip을 사용하고 있습니다. 여기 내 클래스의 :디렉토리의 모든 파일 압축하기
require 'zip/zip'
require 'zip/zipfilesystem'
class Lesson < ActiveRecord::Base
attr_accessible :attachment, :course_id, :goal, :title, :assets_attributes
belongs_to :course
has_many :assets, :dependent => :destroy
accepts_nested_attributes_for :assets, :reject_if => lambda { |a| a[:asset_file_name].blank? }
def bundle
bundle_filename = "public/attachments/#{self.id}/#{self.id}.zip"
Zip::ZipFile.open(bundle_filename, Zip::ZipFile::CREATE) {
|zipfile|
Dir.foreach("public/attachments/#{self.id}") do |item|
zipfile.add(item, "public/attachments/")
end
}
File.chmod(0644, bundle_filename)
self.save
end
end
현재이 내가 원하는 이름으로 ZipFile를 만드는 것입니다,하지만 디렉토리에있는 파일이 제대로 압축되지 않습니다. 그들은 파일로 압축되지 않고 디렉토리로 압축됩니다.
좀 더 자세한 정보를 제공 할 수 있습니까? 예상되는 출력은 무엇이고 실제로 얻는 것은 무엇입니까? * "... 파일로 압축되지만 디렉토리로 ..."*는 몇 가지 방법으로 해석 될 수 있으므로 명확히하십시오. –