我的應用程序創建它不會保存任何地方時,它是由它傳遞給URL(例如,domain.com/letter/2.pdf)渲染的.pdf文件如何在Rails 2.3.5中將prawnto呈現的.pdf附加到電子郵件中?
。
如何在出站電子郵件中將該實際pdf作爲附件。
這裏是我的郵件:
def campaign_email(contact,email)
subject email.subject
recipients contact.email
from 'Me <[email protected]>'
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:
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
注:我硬編碼的本地主機:3000 /我如何可以替換與變量所以在開發它是localhost:3000和生產是否是正確的域?有沒有一種辦法,包括在此路由)
ERROR:我得到一個
Invalid argument - http://localhost:3000/contact_letters/9.pdf
你在軌道2或3? – thatmiddleway 2010-10-15 07:09:32
rails 2.3.5(?) – Angela 2010-10-15 19:11:41
你還可以顯示發送pdf的字母控制器的代碼嗎? – nathanvda 2010-10-20 12:12:29