Загрузить файлы скрепок в формате ZIP

На самом деле я делаю что-то вроде этого:

project          = Project.find(params[:id])  
attachments_list = project.attachments.where{attach_file_size > 0}
assets_list      = project.assets.where{image_file_size > 0}
#Person.where{(name =~ 'Ernie%') & (salary < 50000) | (name =~ 'Joe%') & (salary > 100000)}
file_name  = project.title.downcase.gsub(' ', '_destroy')
file_name  = "#{file_name}.zip"

temp_file  = Tempfile.new("#{file_name}-#{current_user.id}")
Zip::ZipOutputStream.open(temp_file.path) do |zos|
  attachments_list.each do |file|
    zos.put_next_entry(file.title)
    zos.print IO.read(file.attach.path)
  end
  assets_list.each do |file|
    zos.put_next_entry(file.title)
    zos.print IO.read("#{file.image.path}")
  end
end

send_file temp_file.path, :type => 'application/zip',
                          :disposition => 'attachment',
                          :filename => file_name
temp_file.close

Это работает, но у полученных файлов отсутствует расширение, есть идеи?

5
задан Awea 13 February 2012 в 15:36
поделиться