大虾PDF与Rails邮件程序?
我已经成功创建了一封在创建 Kase 时发送的电子邮件,但现在我需要附加由 Prawn 和 Prawno 即时创建的 PDF。基本上,当您访问 application.com/kase/1 等 kase 时,您只需在 URL 后面附加 .pdf,即 application.com/kase/1。
我花了很长时间让 PDF 工作并看起来像我想要的那样,但我不知道如何将 PDF 添加到自动发送电子邮件中 - 主要是因为我不知道如何在它自动生成时为其提供链接。
有没有人设法让它发挥作用?
谢谢,
丹尼
I have successfully created an email that sends on creation of a Kase, but now I need to attach a PDF that is created on the fly by Prawn and Prawno. Basically when you visit a kase such as application.com/kase/1 you just append the URL with .pdf i.e. application.com/kase/1.
I spent ages getting the PDF to work and look how I wanted, but I can't figure out how to add the PDF to an auto sending email - mainly because I cannot work out how to give it a link as it's auto generated.
Has anyone ever managed to get this to work?
Thanks,
Danny
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我想如果你将生成的 pdf 存储在某个地方会更好 - 用于缓存目的等。
但使用当前配置,您可以使用
Net::HTTP
读取生成的页面并附加响应:I suppose it would be better if you store generated pdf somewhere - for caching purposes, etc.
But with current configuration, you can read generated page with
Net::HTTP
and attach response:您确实应该考虑不使用 Prawnto,并创建 Prawn::Document 的子类来执行您需要的操作。然后,在您的控制器和邮件程序代码中,它应该只是:
MyReport.new.render
请参阅有关此的 Prawn 文档:
http://wiki.github.com/sandal/prawn/using-prawn-in-rails
You really should consider just not using Prawnto, and creating a subclass of Prawn::Document to do what you need. Then, in both your controller and your mailer code, it should just be:
MyReport.new.render
See the Prawn documentation on this:
http://wiki.github.com/sandal/prawn/using-prawn-in-rails
对于较新的,您实际上不需要再次发送请求,当您可以时 ::
不这样做 :: 只需
这样做 ::
不要
send_data
,只需在电子邮件附件中呈现该 pdf正如第一个片段中提到的。事实上,我只是在github上写了一个Gist。
For the newer ones, you dont really need to send a request again, when you can ::
Instead of doing this ::
just do this ::
Do not
send_data
, just render that pdf in your email attachment as mentioned in the first snippet.In fact, i just wrote a Gist on github.
这段代码对我有用
This code works for me