Ruby rake任务中的Rails ActionMailer附件未按预期工作

Ruby rake任务中的Rails ActionMailer附件未按预期工作,ruby,ruby-on-rails-3,actionmailer,Ruby,Ruby On Rails 3,Actionmailer,在rake测试中,我以这种方式调用ActionMailer::Base: namespace :mine do desc "it sends emails" mailer = ActionMailer::Base.mail(:from => 'whoever', :to => 'whoemever', :subject => "hi there") do |format| format.text do render :text =>

在rake测试中,我以这种方式调用ActionMailer::Base:

namespace :mine do
  desc "it sends emails"
  mailer = ActionMailer::Base.mail(:from => 'whoever', :to => 'whoemever', :subject => "hi        there") do |format|
    format.text do
      render :text => 'my list'
    end
  end
  mailer.attachments['myfile.csv'] = { :content => File.read('/tmp/file.csv'),
                                             :mime_type => 'text/csv'
                                           }
  mailer.deliver
end
邮件会被发送,但附件会被放入邮件正文中..如下所示:

— Date: Mon, 01 Jul 2013 16:26:25 -0400 Mime-Version: 1.0 Content-Type: text/csv;

charset=UTF-8
Content-Transfer-Encoding: 7bit Content-Disposition: attachment;

filename=my_file.csv

然后是文件的转储。你知道为什么会发生这种情况吗?

可能是因为无论你使用什么客户端来查看邮件,都是以这种方式呈现附件的,而且附件实际上是正确的,正如你指定的那样?看起来不是这样。我在浏览器中尝试了sparrow、apple mail和gmail:/作为一个实验,您可能希望尝试将其作为内联附件发送(
attachments.inline[…]=
),并查看其行为是否相同。但是,我找不到任何可以将默认值发送到内联的地方。@PeterAlfvin,因此我找到了一个解决方案。我必须创建一个单独的带有视图的mailer类。这似乎出于某种原因起了作用。我不太清楚为什么没有