【发布时间】:2012-03-17 01:40:37
【问题描述】:
我正在尝试制作一个表单,该表单将使用 Action Mailer 发送带有附件的电子邮件。我没有使用模型来支持我正在上传的对象。我想将文件直接附加到邮件中,而不必将其保存到服务器硬盘上。在我的控制器中:
def create
attachment = params[:attachment].read
ApplicationRequestMailer.send_application_to_be_entered(current_user.member, attachment).deliver
render :nothing => true
end
在我的邮件中:
class ApplicationRequestMailer < ActionMailer::Base
def send_application_to_be_entered(member, file)
attachment[file.origional_name] = file.read
mail(:to => 'test@test.com', :subject => "To Be Entered")
end
end
有没有办法做到这一点?还是我需要先使用回形针之类的东西保存文件?
【问题讨论】:
-
您尝试过这种方法吗?我认为它应该可以工作,除了你正在读取数据两次......
标签: ruby-on-rails ruby-on-rails-3 actionmailer