Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb Monogid4 Gridfs连接失败_Mongodb_Ruby On Rails 4_Mongoid_Carrierwave_Gridfs - Fatal编程技术网

Mongodb Monogid4 Gridfs连接失败

Mongodb Monogid4 Gridfs连接失败,mongodb,ruby-on-rails-4,mongoid,carrierwave,gridfs,Mongodb,Ruby On Rails 4,Mongoid,Carrierwave,Gridfs,我在Rails4、Mongoid4和Gridfs上工作。我我无法连接gridfs文件系统 class GridfsController < ApplicationController def serve gridfs_path = env["PATH_INFO"].gsub("/uploads/", "") begin gridfs_file = Mongo::GridFileSystem.new(Mongo::DB.new('database_name',

我在Rails4、Mongoid4和Gridfs上工作。我我无法连接gridfs文件系统

class GridfsController < ApplicationController
  def serve
    gridfs_path = env["PATH_INFO"].gsub("/uploads/", "")
    begin
     gridfs_file = Mongo::GridFileSystem.new(Mongo::DB.new('database_name', Mongo::Connection.new('localhost'))).open(gridfs_path, 'r')
    self.response_body = gridfs_file.read
    self.content_type = gridfs_file.content_type
   rescue Exception => e
    self.status = :file_not_found
    self.content_type = 'text/plain'
    self.response_body = ''
    raise e
  end
 end
end
class GridfsControllere
self.status=:未找到文件
self.content\u type='text/plain'
self.response_body=“”
提高e
终止
终止
终止
获取此错误

NameError(未初始化的常量GridfsController::Mongo):
app/controllers/gridfs\u controller.rb:7:in'serve'

Mongoid不使用“官方”Ruby驱动程序与MongoDB对话,这就是它的来源。Mongoid经常和MongoDB聊天,而Moped对GridFS一无所知

AFAIK通常的GridFS解决方案用于与GridFS对话:

self.response_body = Mongoid::GridFs[gridfs_path].data
或者如果您有
id
而不是路径:

self.response_body = Mongoid::GridFs.get(gridfs_id).data

这里有一个适用于轻便摩托车驾驶员的gridfs规范的实现:

这比加载两个驱动程序(轻便摩托车和mongo ruby驱动程序)要好