我正在尝试将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_pdf
gem.trying从pdf
生成html
view
方法
controller
def send_invoice_email
CompanyMailer.invoice(@invoise.id).deliver
redirect_to invoices_path, notice: 'Invoice Sent successfully.'
end
中的逻辑:
mailer
<{1}} 中的方法
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>
答案 0 :(得分:0)
问题已修复。我不需要在网址中传递id。我只需要通过render_to_string(template: 'invoices/show_pdf_invoice.pdf.erb')