Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 无法在rails中的恶意pdf生成的电子邮件中发送pdf附件?_Ruby On Rails_Email Attachments_Wicked Pdf - Fatal编程技术网

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”)