无法在 Rails 中从 wicked-PDF 生成的电子邮件中发送 PDF 附件?



我正在尝试将pdf作为电子邮件中的attachment发送。 但收到错误。

ctionView::MissingTemplate at /invoises/BRUqWOeEVNSN6GCwxQqLGg%253D%253D/send_invoice_email Missing template invoises/#{invoise.id}/show_pdf_invoice.pdf.erb with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :m

我正在使用wicked_pdfgem.试图从htmlview生成pdf

方法在controller

def send_invoice_email
CompanyMailer.invoice(@invoise.id).deliver
redirect_to invoices_path, notice: 'Invoice Sent successfully.' 
end

mailer逻辑:

def invoice(invoice)
invoice = Invoice.find(invoice)
attachments["invoice.pdf"] = WickedPdf.new.pdf_from_string(
render_to_string(:pdf => "invoice",:template => 'invoices/#{invoice.id}/show_pdf_invoice.pdf.erb')
)
mail(to: "abc@gmail.com", subject: 'Your todo PDF is attached')
end

方法在controller

def show_pdf_invoice
respond_to do |format|
format.html { render :layout => false }
format.pdf do
render pdf: "show_pdf_invoice"
#render :pdf => "pdf"#, :layout => 'pdf.html.erb'
end
end
end

并在invoices/show_pdf_invoice.pdf.erb

<h1>this is pdf invoice.<h1>

并在company_mailer/invoice.html.erb

please find attached pdf.

问题已修复。 我不需要在网址中传递 ID。 我只需要传递render_to_string(template: 'invoices/show_pdf_invoice.pdf.erb')

最新更新