5

我有一个 ActionMailer 设置,可以从 S3 发送带有附件的电子邮件。我这样做是这样的:

def job_apply(current_tenant, applicant)
   @current_tenant = current_tenant
   @applicant = applicant

   file = open(applicant.resume.url).read
   attachments[applicant.resume] = file

   email_with_name = "#{@current_tenant.name} <#{@current_tenant.help_email}>"
   mail(from: email_with_name, to: applicant.job.apply_email, subject: "New Job Application")
 end

application.resume.url 返回一个正确的 URL,我可以在浏览器中打开它并检索文件,但是我收到以下错误:

Message undefined method `ascii_only?' for #<ApplicantResumeUploader:0x007fe6bc5c28a8>
File    /Users/cmalpeli/.rvm/gems/ruby-1.9.3-p194@job_board/gems/mail-2.4.4/lib/mail/encodings.rb
Line    103

这是 encodings.rb 中的代码:

 98     def Encodings.decode_encode(str, output_type)
 99       case
 100       when output_type == :decode
 101         Encodings.value_decode(str)
 102       else
 103         if str.ascii_only?
 104           str
 105         else
 106           Encodings.b_value_encode(str, find_encoding(str))
 107         end
 108       end

我有点不知所措从这里去哪里......

任何帮助,将不胜感激...

4

1 回答 1

4

问题出在您的applicant.resume字符串中attachments[applicant.resume]。如果这不是字符串(如 JavaScript 对象),也不是可以代表您附加到电子邮件的文件的文件名,那么这将导致 ActionMailer 出现问题。

在继续之前验证该applicant.resume字符串确实是一个文件名foo.pdf或类似。resume.doc

于 2012-12-10T00:40:36.433 回答