WickedPDF发送空白pdf作为邮件附件


if params[:invoice_id].presence
@invoice = Invoice.find(params[:invoice_id])
attachments['invoice.pdf'] = WickedPdf.new.pdf_from_string(
render_to_string(
template: 'invoices/service',
locals: { current_user: }
)
)
end

我已经从wickedpdf中附加了一个PDF,但是在发送附件后,它是空白的。

我正在尝试发送附件在Ruby on Rails与ActionMailer与PDF作为附件。

通过查看Wicked PDF文档中的示例,看起来您在render_to_string方法中缺少了layout选项。

我建议这样做:

if params[:invoice_id].presence
@invoice = Invoice.find(params[:invoice_id])
attachments['invoice.pdf'] = WickedPdf.new.pdf_from_string(
render_to_string(
template: 'invoices/service',
locals: { current_user: },
# add this line and change the value with the right pdf layout path
layout: 'layouts/pdf' 
)
)
end

最新更新