Wicked_pdf在开发中工作正常,但不在生产中

我一直在使用wicked_pdf在Rails中生成一些PDF,并且它在我的开发环境中工作正常,但是当我尝试在我的生产环境中生成一个错误时,我得到500错误(但我的日志中没有特定错误)。 我注意到的第一件事是wkhtmltopdf二进制文件位于我的生产盒上的不同位置,所以我将以下内容添加到我的wicked_pdf.rb初始化程序中:

if Rails.env == "production" WickedPdf.config = { :exe_path => '/usr/bin/wkhtmltopdf' } end 

这是我在控制器中调用它的方式:

  def certificate @inspection = Inspection.find(params[:id]) @council = Council.find(@inspection.councilid) respond_to do |format| format.pdf do render :pdf => @inspection.slug, :show_as_html => params[:debug].present?, :margin => {:top => 0, :bottom => 0, :left => 0, :right => 0} end end end 

这是我的观点的内容:

 # certificate.pdf.erb      body { margin: 0; padding: 0; font-family: "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, sans-serif; } img#bg { width: 800px; height: 1130px; position: absolute; } #date p, #council p { line-height: 17px; font-size: 12px; } #council { position: absolute; top: 650px; left: 445px; } #logo { position: absolute; top: 965px; left: 98px; } #logo img { height: 65px; } #address { position: absolute; top: 425px; left: 300px; } #address p { font-size: 22px; line-height: 27px; } #date { position: absolute; top: 650px; left: 98px; }     "bg" %> 


<%= @inspection.address("
").html_safe %>



Tel:

当我将debug=true添加到查询字符串时,它似乎生成OK(并且wicked_pdf_image_tag帮助程序似乎生成了正确的位置,这似乎是Rails 3.1中的问题)。 有任何想法吗? 我是Ruby / Rails的新手,所以请保持温和!

如果让Bundler担心将依赖关系源化为wkthmltopdf,那么这样做要容易得多。 你可以通过安装它来做到这一点:

 gem "wkhtmltopdf-binary" 

然后运行bundle install。 之后,您应该能够删除自定义exe_path规范,它应该可以正常工作。 如果这不起作用,请告诉我。

如果生产环境中仍未显示静止图像,请尝试

 image_tag wicked_pdf_asset_base64('image.png')