我在我的Rails应用程序中使用WickedPDF来生成PDF文件。它在我的本地机器上运行良好。在生产中,我在日志中看到以下错误:
Started GET "/financieel/facturen/2.pdf" for 81.205.74.167 at 2012-09-19 14:58:37 +0200
Processing by InvoicesController#show as PDF
Parameters: {"id"=>"2"}
***************WICKED***************
Rendered invoices/show.pdf.haml (6.9ms)
Completed 500 Internal Server Error in 38ms
NoMethodError (undefined method `chomp' for nil:NilClass):
app/controllers/invoices_controller.rb:22:in `block (2 levels) in show'
app/controllers/invoices_controller.rb:17:in `show'
在invoices_controller.rb中没有什么不寻常之处:
format.pdf do
render pdf: 'factuur'
end
答案 0 :(得分:1)
wicked_pdf试图猜测你的wkhtmltopdf二进制文件的位置可能会导致你的麻烦:https://github.com/mileszs/wicked_pdf/blob/master/lib/wicked_pdf.rb#L207
如果服务器上实际安装了wkhtmltopdf,那么最好的办法是在初始化程序中专门设置wkhtmltopdf的路径,如下所示:
# config/initializers/wicked_pdf.rb
WickedPdf.config = { :exe_path => '/opt/bin/wkthmltopdf' } # or wherever it actually is