Rails:将用大虾生成的pdf通过电子邮件发送到ActionMailer发送的电子邮件吗?

发布于 2024-09-11 12:17:32 字数 280 浏览 2 评论 0原文

我有一个电子商务应用程序。我正在使用 Prawn 生成 pdf 订单发票。我正在使用标准的虾设置。在views/admin/orders中,我有一个名为show.pdf.prawn的文件。当卖家在其管理部分查看订单时,他单击一个链接,打开 PDF 版本的订单/显示视图。这一切都很完美。

现在,棘手的部分。订单完成后,我会向卖家发送一封电子邮件。我想做的是将订单/演出的 pdf 发票版本附加到该电子邮件中。可以这样做吗?有关电子邮件附件的文档非常有限,我无法找到完成我所描述的工作流程的资源。

任何指导表示赞赏。

I have an ecommerce app. I'm using Prawn to generate pdf invoices of orders. I'm using a standard Prawn setup. In views/admin/orders, I have a file called show.pdf.prawn. When the seller is viewing an order in his admin section, he clicks a link that opens the pdf version of the orders/show view. This all works perfectly.

Now, the tricky part. When an order is completed, I send an email to the seller. What I'd like to do is attach the pdf invoice version of orders/show to that email. Is it possible to do this? The documentation on email attachments is pretty limited and I haven't been able to find resources that go through the workflow that I'm describing.

Any guidance is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九歌凝 2024-09-18 12:17:32

使用 ActionMailer 通过电子邮件发送附件相当容易:

class InvoiceMailer < ActionMailer::Base

  def email_with_attachment(pdf_invoice)
    .
    .
    .

    attachment "application/pdf" do |a|
      a.filename = "some_invoice.pdf"
      a.body = pdf_invoice
    end
  end

end

您可能遇到的一个问题是在 prawnto 方法之外生成 pdf 文件(当使用 prawnto 插件时)-
如果是这种情况,我强烈建议您使用这种方法 相反。

Sending an attachment with an email is fairly easy with ActionMailer:

class InvoiceMailer < ActionMailer::Base

  def email_with_attachment(pdf_invoice)
    .
    .
    .

    attachment "application/pdf" do |a|
      a.filename = "some_invoice.pdf"
      a.body = pdf_invoice
    end
  end

end

One problem you might have with this is generating the pdf file outside of the prawnto method (when using the prawnto plugin)-
If this is is the case I strongly recommend you to use this approach instead.

拧巴小姐 2024-09-18 12:17:32

我遇到了同样的问题,我设法通过从模型生成 pdf 来做到这一点,比评估模板容易得多。我在这里回复了答案:

将 Prawn PDF 保存为回形针附件?

I had the same problem, i managed to do it by generating the pdf from a model, much easier than evaluating the template. I replied with the answer here :

Save a Prawn PDF as a Paperclip attachment?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文