简体   繁体   中英

Rails 4 Refile and mailer

I am using refile gem to upload documents. 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 ? 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

2) Can I change dynamically location of store files?

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. 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:

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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