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

问题描述 投票:0回答:1
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 中发送附件。

ruby-on-rails ruby email-attachments wicked-pdf
1个回答
0
投票

通过查看 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
© www.soinside.com 2019 - 2024. All rights reserved.