回形针+ ActionMailer-添加附件? [英] paperclip + ActionMailer - Adding an attachment?

查看:98
本文介绍了回形针+ ActionMailer-添加附件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个回形针文件,希望将其添加为电子邮件附件...。

I have a paperclip'd file that I want to add as an attachment to my email....

UserMailer类< ActionMailer :: Base
def XXXXXX_notification(record)
@record = record

class UserMailer < ActionMailer::Base def XXXXXX_notification(record) @record = record

  attachments ??? How to add a paperclip file?

  mail( :to => "#{record.email}", 
        :subject => "XXXXXXXX"
        )
end

似乎没有关于google的话题,如果您有任何想法,我很想听听: )

There seems to be nothing on the topic via google, if you have any ideas, I'd love to hear it :)

谢谢

更新

  @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


推荐答案

来自Ruby on Rails指南(只能通过必应):

From the Ruby on Rails guides (only reachable through Bing):

http://guides.rubyonrails.org/action_mailer_basics.html#sending-emails-with-attachments

剩下的就是将附件(如果在S3中)下载到 file 对象或对其进行访问,它存储在本地。尝试使用 open-uri

All that is left is to download the attachment (if in S3) to a file object or access it it is stored locally. Try using open-uri.

这篇关于回形针+ ActionMailer-添加附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆