The*_*xit 10 ruby-on-rails actionmailer paperclip ruby-on-rails-3
我有一个回形针文件,我想添加为我的电子邮件的附件....
class UserMailer <ActionMailer :: Base def XXXXXX_notification(record)@record = record
attachments ??? How to add a paperclip file?
mail( :to => "#{record.email}",
:subject => "XXXXXXXX"
)
end
Run Code Online (Sandbox Code Playgroud)
通过谷歌似乎没有任何关于这个话题,如果你有什么想法,我很想听听:)
谢谢
UPDATE
@comment.attachments.each do |a|
tempfile = File.new("#{Rails.root.to_s}/tmp/#{a.attachment_file_name}", "w")
tempfile << open(a.authenticated_url())
tempfile.puts
attachments[a.attachment_file_name] = File.read("#{Rails.root.to_s}/tmp/#{a.attachment_file_name}")
# Delete it tempfile
#File.delete("#{Rails.root.to_s}/tmp/#{a.filename}")
end
Run Code Online (Sandbox Code Playgroud)
它已经得到了回答,但我只想分享一种略有不同的方式:
这是我的模特报告.我正在使用Paperclip.
class Report < ActiveRecord::Base
has_attached_file :pdf_file
...
end
Run Code Online (Sandbox Code Playgroud)
这是我的邮件ReportMailer
class ReportMailer < ActionMailer::Base
def monthly_report_email(emails, report)
attachments[report.pdf_file_file_name] = File.read(report.pdf_file.path)
mail(:to => emails, :subject => 'monthly report')
end
end
Run Code Online (Sandbox Code Playgroud)
来自 Ruby on Rails 指南(只能通过Bing访问):
http://guides.rubyonrails.org/action_mailer_basics.html#sending-emails-with-attachments
剩下的就是将附件(如果在 S3 中)下载到文件对象或访问本地存储的附件。尝试使用open-uri。
| 归档时间: |
|
| 查看次数: |
4994 次 |
| 最近记录: |