ruby on rails -什么是模块ActionController::UploadedFile的替代品



我已经尝试了太长时间,以获得docaptor rails示例将生成的PDF保存到使用rails 3.0.7的Amazon S3。似乎ActionController::UploadedFile已被ActionDispatch::Http::UploadedFile所取代,但当我尝试使用该类扩展我的文件对象时,我得到了错误'wrong argument type Class (expected Module)'

来源如下。我是否错误地使用了"extend"?我要怎么做我想做的事?实际上,我所要做的就是指定要用Paperclip上传到S3的文件的名称。

def create_pdfdoc(document_content)
  DocRaptor.create(  :document_content => document_content, 
                     :document_type    => 'pdf',
                     :name             => self.title.tr(' ','_'),
                     :test             => true) do |file, response|
      file.extend(ActionDispatch::Http::UploadedFile)
      file.content_type  = response.headers["content-type"]
      name = self.title.strip.gsub(/s/, "_").gsub(/W/, "").underscore.downcase
      file.original_filename = "#{name}.pdf"
      if response.code == 200
        self.pdfdoc = file
      end
  end
end

最后,我把它打包了。我将一个局部变量设置为要保存的文件的名称(self.pdfdoc),然后回收针处理其余的工作。它成功了。

没有什么比三年后回答一个问题更好的了…

对于将来遇到这种情况的人来说,这是"正确"的方法:

DocRaptor.create(options) do |file, response|
   upload = ActionDispatch::Http::UploadedFile.new({
      :filename => 'test.pdf',
      :type => response.headers["content-type"],
      :tempfile => file
    })
end

相关内容

  • 没有找到相关文章

最新更新