我在fixture_file_upload使用载波安装的现场的工厂中使用。所以,我有以下内容:
模型:
class Job < ActiveRecord::base
  mount_uploader :translated_xliff, XliffUploader
end
工厂:
FactoryGirl.define do
  factory :job do
    translated_xliff { fixture_file_upload(
                           Rails.root.join(*%w[spec fixtures text.xliff])) }
   end
end
这很好,但现在我在我的 Job 控制器上添加了一个动作,让人们下载这个文件。为此,我有以下行动:
class JobsController < ApplicationController
  def xliff
    job = Job.find(params[:id])
    send_file(job.translated_xliff.path, disposition: 'attachment')
  end
end
但这引发了一个例外send_file:
Exception: no implicit conversion of nil into String
使用byebug我发现两者都是和path,所以我想工厂女孩在添加文件时失败了。filenil
我正在使用 rails 3.2 和 ruby 2.0。我究竟做错了什么?我应该模拟路径方法,还是以不同的方式上传文件?