我在我的Rails 4应用程序中使用wick_pdf将几个html模板转换为pdf文件。然后我将这些pdf附加到出站电子邮件中。电子邮件和pdf正在正确发送,但还有一个空白的pdf(有时不完全)与我想要的pdf一起发送。我在下面附上了我的代码。如果您有任何建议,请告诉我。
def approval_notification(id)
@user = User.find(id)
esign = WickedPdf.new.pdf_from_string(render_to_string pdf: "esign", template: "disclosures/pdfs/esign_pdf.html.erb", formats: :html, encoding: "UTF-8")
mail(:to => @user.email, :subject => 'Congratulations! You have been approved!') do |format|
format.html
format.pdf do
attachments['Electronic_Signature.pdf'] = esign
end
end
end
更新
好吧,我设法解决了这个问题。我仍然不完全明白什么是错的所以请解释一下你是否知道。修改后的代码如下:
def approval_notification(id)
@user = User.find(id)
esign = WickedPdf.new.pdf_from_string(render_to_string pdf: "esign", template: "disclosures/pdfs/esign_pdf.html.erb", formats: :html, encoding: "UTF-8")
attachments['Electronic_Signature.pdf'] = esign
mail(:to => @user.email, :subject => 'Congratulations! You have been approved!')
end