【发布时间】:2016-12-16 23:32:44
【问题描述】:
我正在尝试在电子邮件中将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.trying 从html view 生成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.
【问题讨论】:
-
不太熟悉
render_to_string的工作原理,但看起来您的字符串插值设置不正确。更改为"invoices/#{invoice.id}/show_pdf_invoice.pdf.erb"使用双引号作为字符串插值的最外层引号。 -
我改变了那行。还是一样的错误。
-
更改为
render_to_string(template: 'invoices/show_pdf_invoice.pdf.erb')
标签: ruby-on-rails email-attachments wicked-pdf