我正在研究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得到这个错误
NameError (未初始化常量GridfsController::Mongo):
app/controllers/gridfs_控制员.in:7:in‘’
发布于 2014-01-06 06:54:06
Mongoid不使用“官方”Ruby驱动程序与MongoDB对话,这就是Mongo::GridFileSystem的来源。蒙古人用摩托和MongoDB交谈,而摩托对GridFS一无所知。
AFAIK通常的GridFS解决方案是使用文件系统与GridFS对话:
self.response_body = Mongoid::GridFs[gridfs_path].data或者如果您使用的是id而不是路径:
self.response_body = Mongoid::GridFs.get(gridfs_id).data发布于 2014-06-25 13:24:08
这里有一个针对摩托驱动程序的gridfs规范的实现:摩托-格雷斯。
这比装载两个司机(摩托和芒果红宝石司机)要好。
https://stackoverflow.com/questions/20944010
复制相似问题