简体   繁体   English

Rails 4重新归档和邮件

[英]Rails 4 Refile and mailer

I am using refile gem to upload documents. 我正在使用refile gem上传文档。 Documents once uploaded are then sent to some recipients by email. 上传后的文档随后通过电子邮件发送给某些收件人。

1) How can I add to mail as attachments the documents stored with refile ? 1)如何将随refile存储的文档作为附件添加到邮件中? below it is not working 下面它不起作用

I have the following in DB: 我在数据库中有以下内容:

commented_id, varchar
commented_filename, varchar
commented_size, varchar
commented_content_type, varchar

attach files: 附加文件:

@revisions.each do |revision|
  mail.attachments["#{revision.file_filename}"] = File.read(revision.file)
end

error: no implicit conversion of Refile::File into String 错误:没有Refile :: File到String的隐式转换

2) Can I change dynamically location of store files? 2)我可以动态更改存储文件的位置吗?

I was able to attach files to mailers from the objects individually inside my application_mailer.rb file by calling read on the file directly, rather than using #read as a File class method. 通过直接调用文件上的read,而不是使用#read作为File类方法,我能够将文件分别从application_mailer.rb文件中的对象附加到邮件程序。 I'm using ActionMailer in rails and the mailer method looks like this, assuming that revision is the database object that has the commented file attached as described in your db: 我在rails中使用ActionMailer,并且mailer方法看起来像这样,假设revision是数据库对象,该数据库对象具有附加的commented文件,如您的db中所述:

def send_mailer(revision)
   @revision = revision

   attachments["filename_here"] = @revision.commented.read
   mail(to: "email@email.com", subject: "Here's your file!")
end

Not sure if you're using ActionMailer as well but if you are, this might work! 不知道您是否也在使用ActionMailer,但是如果您使用的话,这可能会起作用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM