【发布时间】:2013-02-27 21:30:22
【问题描述】:
在我的发票系统中,我想要一个备份功能,将所有发票一次下载到一个 zip 文件中。 该系统在 heroku 上运行 - 所以只能临时保存 pdf。
我已经安装了 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
这以消息结束 BillsController#zip_all_bills 关闭流中的 IOError
【问题讨论】:
-
您好,我也遇到了和您一样的问题。我有一个调用应用程序,我想使用 wicked_pdf 从生成的 PDFS 生成 ZIP。我找不到这个问题的适当解决方案。如有任何建议,我将不胜感激。
标签: ruby-on-rails-3 heroku wicked-pdf rubyzip