Rails でいくつかの PDF を生成するために wicked_pdf を使用しており、私の開発環境では問題なく動作していますが、実稼働環境で 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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
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;
}
</style>
</head>
<body>
<%= wicked_pdf_image_tag "certificate#{@inspection.rating}.jpg", :id => "bg" %>
<div id="address">
<p><%= @inspection.name %><br />
<%= @inspection.address("<br />").html_safe %> </p>
</div>
<div id="date">
<p><%= @inspection.date.strftime("%B %d %Y") %></p>
</div>
<div id="council">
<p><%= @council.address.html_safe %><br /><br />
<strong>Tel: </strong><%= @council.tel %></p>
</div>
<div id="logo">
<%= wicked_pdf_image_tag "certificates/#{@council.logo}.png" %>
</div>
</body>
</html>
debug=true
クエリ文字列に追加すると、OK が生成されるようです (そして、wicked_pdf_image_tag
ヘルパーは正しい場所を生成するように見えますが、これは Rails 3.1 の落とし穴のようです)。何か案は?Ruby/Rails初心者なので、お手柔らかにお願いします!