gpt4 book ai didi

ruby-on-rails - 如何在 Rails 2.3.5 中将 prawnto-rendered .pdf 附加到电子邮件中?

转载 作者:行者123 更新时间:2023-12-04 02:21:51 25 4
gpt4 key购买 nike

我的应用程序通过将其传递给 URL(例如,domain.com/letter/2.pdf)来在呈现时创建一个 .pdf 文件

它不会在任何地方保存。

如何使实际的 pdf 成为出站电子邮件中的附件。

这是我的邮件:

  def campaign_email(contact,email)
subject email.subject
recipients contact.email
from 'Me <me@me.com>'
sent_on Date.today

attachment = File.read("http://localhost:3000/contact_letters/#{attachment.id}.pdf")

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

这是创建/渲染 PDF 的 Controller :
def create
@contact_letter = ContactLetter.new(params[:contact_letter])

@contact = Contact.find_by_id(@contact_letter.contact_id)
@letter = Letter.find_by_id(@contact_letter.letter_id)

if @contact_letter.save
flash[:notice] = "Successfully created contact letter."

#redirect_to contact_path(@contact_letter.contact_id)
redirect_to contact_letter_path(@contact_letter, :format => 'pdf')
else
render :action => 'new'
end
end

注意:我硬编码了 localhost:3000/我怎样才能用一个变量替换它,以便在开发中它是 localhost:3000 而在生产中它是正确的域?有没有办法在其中包含路由?)

错误:我得到一个

Invalid argument - http://localhost:3000/contact_letters/9.pdf

最佳答案

这是 rails 2 的示例

class ApplicationMailer < ActionMailer::Base
# attachments
def signup_notification(recipient, letter)
recipients recipient.email_address_with_name
subject "New account information"
from "system@example.com"

attachment :content_type => "image/jpeg",
:body => File.read("an-image.jpg")

attachment "application/pdf" do |a|
a.body = letter
end
end
end

在您看来或在您调用方法的任何地方:
ApplicationMailer.deliver_signup_notification(letter)

关于ruby-on-rails - 如何在 Rails 2.3.5 中将 prawnto-rendered .pdf 附加到电子邮件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3940113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com