执行rake mongo:mongrate时出现“未初始化的常量MongoMapper :: Base”错误

时间:2011-01-31 05:17:25

标签: ruby-on-rails mongodb rubygems mongomapper

我在“rake mongo:mongrate”尝试期间遇到以下错误:

$ rake mongo:mongrate --trace
(in /home/mei/Jobfully)
** Invoke mongo:mongrate (first_time)
** Invoke environment (first_time)
** Execute environment

** Execute mongo:mongrate
==  AddPricingPlans: migrating ================================================
-- add_column(:users, :plan_id, :string)
rake aborted!
uninitialized constant MongoMapper::Base
/home/mei/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:440:in `rescue in load_missing_constant'

我的Gemfile中有以下内容 -

gem 'rake', '~>0.8'
gem 'mongo',        '= 1.0.7'  # must be same version as bson/bson_ext
gem 'bson',         '= 1.0.4'  # must be same version as bson_ext/mongo
gem 'bson_ext',     '= 1.0.4'  # must be same version as bson/mongo
gem 'mongo_mapper', '~> 0.8.2'

我还在Rakefile中添加了以下行 -

import 'vendor/plugins/mongrations/lib/tasks/mongo.rake'

有关如何解决此问题的任何想法?感谢。

1 个答案:

答案 0 :(得分:1)

MongoMapper::Base在去年某个时候被弃用(它甚至不再存在!)。您现在需要MongoMapper.connection中的lib/mongo_mapper/mongrations.rbdef connection而不是MongoMapper::Base.connection

我不确定它什么时候坏了,但是做出这个改变对我来说已经固定了。

如果您想要进行monkeypatch,可以使用:

module MongoMapper
  class Base
    def self.connection
      MongoMapper.connection
    end
  end
end