MongoId - 未初始化的常量App :: Mongo(NameError)“

时间:2012-11-07 14:04:49

标签: ruby mongodb gem sinatra

在Sinatra app我有

 #config.rb
  require 'mongoid'

  class App
    configure do 
        Mongoid.configure do |config|
          name = "my_db"
          host = "localhost"
          config.master = Mongo::Connection.new.db(name)
          config.slaves = [Mongo::Connection.new(host, 27017, :slave_ok => true).db(name)]
          config.persist_in_safe_mode = false
        end
      end
    end

    #Gemfile
    gem "mongoid", "~> 3.0.0"
    gem "bson_ext"

它给了我一个错误“`const_missing':未初始化的常量App :: Mongo(NameError)” 我该如何解决?

1 个答案:

答案 0 :(得分:1)

这是因为Mongoid 3.x不再使用10Gen Ruby驱动程序,因此Mongo模块将不会加载require 'mongoid'模块。您需要使用新的Mongoid.load!方法。您可能需要更改config.yml文件,因为语法已更改。请参阅http://mongoid.org/en/mongoid/docs/installation.html