未初始化的常量BSON :: InvalidObjectId rack-gridfs gem的错误

时间:2015-10-28 16:43:07

标签: ruby mongodb rack gridfs

我有一些图像存储在Mongodb的GridFs中,我想得到图像的网址。我安装了rack-gridfs gem,这里是gem的链接:https://github.com/skinandbones/rack-gridfs/

我目前正在使用Rails 4.0.0,所以我只编辑了config / routes.rb,如下所示:

Rails.application.routes.draw do
  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)

  namespace :admin do
    resources :users do    
      resources :annotations
    end
    mount Rack::GridFS::Endpoint.new(:db =>Mongoid::Config.sessions[:default]), :at => "gridfs"
  end
end

但是当我尝试http://localhost:3000/admin/gridfs/54f5ece4e4b0e8f8dcce15d0时,出现错误为" 未初始化的常量BSON :: InvalidObjectId "。我尝试http://localhost:3000/admin/gridfs时出现了同样的错误。我从Mongodb的fs.files集合中获取了id。

以下是fs.files中的图像示例:

{ "_id" : ObjectId("55314ad2e4b08b15f51ddf65"), "metadata" : { "_id" :  "ced7ca7f-e287-45b5-a58b-70b9f397a253", "media_id" : "2ED3539B-E62B-4EA1-8224-3EE0DA8386E8.jpg", "data_point_id" : "1A48F01F-725F-49FD-A2A2-347D71910693", "size" : NumberLong(354010), "content_type" : "image/jpeg"}, "filename" : "ced7ca7f-e287-45b5-a58b-70b9f397a253", "aliases" : null, "chunkSize" : NumberLong(261120), "uploadDate" : ISODate("2015-04-17T18:02:58.880Z"), "length" : NumberLong(354010), "contentType" : "image/jpeg", "md5" : "e01669ddc1b26b48086ec1c700004f00" }

非常感谢任何帮助,非常感谢!!!

0 个答案:

没有答案