ruby-on-rails – 访问文件上载而不保存文件,然后通过电子邮件将
发布时间:2020-12-17 02:30:54 所属栏目:百科 来源:网络整理
导读:我正在尝试制作一个表单,使用Action Mailer发送带有附件的电子邮件.我没有使用模型来支持我上传的对象.我想直接将文件附加到邮件,而不必将其保存到服务器硬盘驱动器.在我的控制器中: def create attachment = params[:attachment].read ApplicationRequestM
我正在尝试制作一个表单,使用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 有没有办法做到这一点?或者我是否需要先使用回形针等方法保存文件? 解决方法
不确定这是否完全正确,但是它有效:
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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |