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,但在发送附件后,它变成了空白的白页。
我正在尝试使用 ActionMailer 以 PDF 作为附件在 Ruby on Rails 中发送附件。
通过查看 Wicked PDF 文档中的示例,您似乎在
layout
方法中缺少 render_to_string
选项。
我建议这样做:
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