0

Rails 3 で Paperclip の添付ファイルを電子メールで送信しようとしています。

請求書モデル:

class Invoice < ActiveRecord::Base

has_attached_file :attachment,
:url => "http://server/app/attachments/:id/:style/:basename.:extension",
:path => ":rails_root/public/attachments/:id/:style/:basename.:extension"
validates_attachment_presence :attachment
validates_attachment_size :attachment, :less_than => 5.megabytes

end

account_mailer:

  def email_approver(invoice)
    @subject          = 'Invoice Approval Request'
    @body["invoice"]  = invoice
    #attachment  "application/octet-stream" do |a|
          #a.body = File.read(invoice.attachment.to_file.path)
          #a.filename = invoice.attachment_file_name
      #end
    @recipients = [invoice.approver_email, invoice.alternate_approver_email].compact
    @from             = "ADMIN"
    @sent_on          = Time.now
    @headers          = {}    
 end

エラー:

NoMethodError (undefined method `filename=' for #<Mail::Part:0x00000002566dd0>):

何か案は?ありがとう!

4

2 に答える 2

0

このようなことを試しましたか

attachments[invoice.attachment_file_name] = File.read(invoice.attachment.to_file.path)

?

于 2013-01-25T14:23:04.220 に答える
0

これは古い質問ですが、これが私の実用的な解決策です:

attachments[mymodel.attachment.filename] = File.read(mymodel.attachment.path)
于 2016-01-26T09:26:05.107 に答える