PDFKIT 在控制器中而不是在控制台中生成 PDF 时挂起

PDFKIT hangs while generating PDF in controller but not in console

我在尝试使用 PDFKit 生成 PDF 时遇到问题。如果在控制台上发出以下命令:

kit = PDFKit.new("http://localhost:3000/invoices/57f0bf61fc7b3415fc000000")

其次是

kit.to_file("pdfs/invoices/57f0bf61fc7b3415fc000000.pdf")

一切正常,文件已生成。现在,如果我在控制器中有相同的代码,pdf 生成会在第 1 步挂起,并且不会显示任何错误。

如果我尝试 wkhtmltopdf http://localhost:3000/invoices/ivoice_id invoice.pdf 它也有效。

这是为什么?更重要的是,如何解决?

我正在使用 Rails 4.

勾选https://github.com/pdfkit/pdfkit#troubleshooting

如果您在该模板中有一些资产应该由您的本地服务器提供,那么在开发中可能会挂起,具体取决于您的服务器配置。您当前向服务器呈现 PDF "blocks" 的请求,它无法响应后续的资产请求(图像、css、js)。如果可能,从 CDN 为它们提供服务,在开发中使用多进程服务器配置等。