3
在我的發票系統中,我希望有一個備份功能可以在一個zip文件中一次下載所有發票。 此係統在heroku上運行 - 因此只能暫時保存pdf。使用wicked_pdf從生成的PDF生成ZIP
我已經安裝了rubyzip和wicked_pdf gem。
我當前的代碼在控制器:
def zip_all_bills
@bill = Bill.all
if @bill.count > 0
t = Tempfile.new("bill_tmp_#{Time.now}")
Zip::ZipOutputStream.open(t.path) do |z|
@bill.each do |bill|
@bills = bill
@customer = @bills.customer
@customer_name = @customer.name_company_id
t = WickedPdf.new.pdf_from_string(
render :template => '/bills/printing.html.erb',
:disposition => "attachment",
:margin => { :bottom => 23 },
:footer => { :html => { :template => 'pdf/footer.pdf.erb' } }
)
z.puts("invoice_#{bill.id}")
z.print IO.read(t.path)
end
end
send_file t.path, :type => "application/zip",
:disposition => "attachment",
:filename => "bills_backup"
t.close
end
respond_to do |format|
format.html { redirect_to bills_url }
end
end
這結束與消息 的IOError在BillsController#zip_all_bills關閉流
嗨,我有和你一樣的問題。我有一個invocing應用程序,我想用生成的PDF與wicked_pdf生成ZIP。我無法找到適合此問題的解決方案。我會很感激任何意見。 – 2014-09-05 05:42:58