我正在尝试制作一个表格,该表格将使用 Action Mailer 发送带有附件的电子邮件。我没有使用模型来支持我上传的对象。我想将文件直接附加到邮件中,而不必将其保存到服务器硬盘。在我的 Controller 中:
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
有没有办法做到这一点?还是我需要先使用回形针之类的东西保存文件?
最佳答案
不确定这是否完全正确,但它正在工作:
def create
ApplicationRequestMailer.send_application_to_be_entered(params[:application].read(), params[:application].original_filename).deliver
redirect_to dashboards_path, :notice => "Request Sent."
end
def send_application_to_be_entered(file, filename)
attachments[filename] = file
mail(:to => 'test@test.com', :subject => "Application To Be Entered")
end
关于ruby-on-rails - 访问文件上传而不保存文件,然后将其作为附件通过电子邮件发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8840974/