Ruby on rails 无法在rails中的恶意pdf生成的电子邮件中发送pdf附件?
我正在尝试将Ruby on rails 无法在rails中的恶意pdf生成的电子邮件中发送pdf附件?,ruby-on-rails,email-attachments,wicked-pdf,Ruby On Rails,Email Attachments,Wicked Pdf,我正在尝试将pdf作为电子邮件中的附件发送。但是有一个错误 ActionView::在/invoises/bruqwoeevnsn6gcwxqlgg%253D%253D/send\u invoice\u email中丢失模板 缺少模板invoises/#{invoise.id}/show_pdf_invoice.pdf.erb,带有{:locale=>[:en],:formats=>[:html,:text,:js,:css,:ics,:csv,:vcf,:png,:jpeg,:gif,:bmp
pdf
作为电子邮件中的附件发送。但是有一个错误
ActionView::在/invoises/bruqwoeevnsn6gcwxqlgg%253D%253D/send\u invoice\u email中丢失模板
缺少模板invoises/#{invoise.id}/show_pdf_invoice.pdf.erb,带有{:locale=>[:en],:formats=>[:html,:text,:js,:css,:ics,:csv,:vcf,:png,:jpeg,:gif,:bmp,:tiff,:m
我正在使用wicked\u pdf
gem。试图从html
视图生成pdf
控制器中的方法
def send_invoice_email
CompanyMailer.invoice(@invoise.id).deliver
redirect_to invoices_path, notice: 'Invoice Sent successfully.'
end
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
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
控制器中的方法
def send_invoice_email
CompanyMailer.invoice(@invoise.id).deliver
redirect_to invoices_path, notice: 'Invoice Sent successfully.'
end
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\u pdf\u invoice.pdf.erb
<h1>this is pdf invoice.<h1>
please find attached pdf.
问题已解决。我不需要在url中传递id。我只需要传递呈现到\u字符串(模板:“invoices/show\u pdf\u invoice.pdf.erb”)
问题已解决。我不需要在url中传递id。我只需要传递呈现到\u字符串(模板:“invoices/show\u pdf\u invoice.pdf.erb”)
不太熟悉渲染到字符串的工作方式,但看起来字符串插值设置不正确。更改为“invoices/{invoice.id}/show\u pdf\u invoice.pdf.erb”
使用双引号作为字符串插值的最外层引号。我更改了该行。仍然是相同的错误。更改为render\u to\u string(模板:“invoices/show\u pdf\u invoice.pdf.erb”)
不太熟悉render_to_string
的工作原理,但您的字符串插值设置似乎不正确。请更改为“invoices/#{invoice.id}/show_pdf_invoice.pdf.erb”
使用双引号作为字符串插值的最外层引号。我更改了该行。仍然是相同的错误。更改为render\u to\u string(模板:“invoices/show\u pdf\u invoice.pdf.erb”)