无法在wicked-pdf在rails中生成的电子邮件中发送pdf附件?

时间:2016-12-16 14:13:26

标签: ruby-on-rails email-attachments wicked-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_pdf gem.trying从pdf生成html view

<{1}}

中的

方法

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>

1 个答案:

答案 0 :(得分:0)

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