0

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?

Mathias
  • 5,642
  • 2
  • 31
  • 46
Fabio
  • 1
  • 1
  • 3

1 Answers1

0

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!

Rachel C.
  • 61
  • 8