【问题标题】:Ruby on Rails and MongoDBRuby on Rails 和 MongoDB
【发布时间】:2012-01-09 07:10:11
【问题描述】:

我有一个新的 Ruby on Rails 安装,我可以在其中看到默认的起始页。

我关注this guide 是为了将 MongoDB 安装到 Rails。

现在运行rake test时出现此错误:

**Notice: C extension not loaded. This is required for optimum MongoDB Ruby driver performance.
  You can install the extension as follows:
  gem install bson_ext

  If you continue to receive this message after installing, make sure that the
  bson_ext gem is in your load path and that the bson_ext and mongo gems are of the same version.

我已经安装了 bson_ext gem,这意味着现在 bson_ext 不在我的加载路径中,或者这些 gem 不是相同的版本。

加载路径在哪里?我怎样才能改变它? 如何检查 gem 是否为同一版本?

【问题讨论】:

    标签: ruby-on-rails ruby mongodb rubygems mongodb-ruby


    【解决方案1】:

    打开 Gemfile(在 Rails 应用的根目录中)并添加一行:bson_ext

    你应该有:

    gem mongo
    gem bson_ext
    

    这里还有来自10gen docs 的关于在 Rails 中运行测试的更多信息:

    运行测试 需要稍作修改才能使 rake 测试正常工作(感谢 John P. Wood)。创建一个包含以下内容的文件 lib/tasks/mongo.rake:

    namespace :db do
      namespace :test do
        task :prepare do
          # Stub out for MongoDB
        end
      end
    end
    

    现在各种 rake 测试任务将正常运行。有关详细信息,请参阅 John 的帖子。

    他们还引用了John Wood's post,这非常好。

    【讨论】:

    • 您指的是与我的问题相同的文章。
    【解决方案2】:

    如果您使用的是 Ruby on Rails 3+,您应该检查您的 Gemfile 中是否引用了 bson_ext gem。

    【讨论】:

    • 不是,怎么添加?抱歉,我是 Rails 新手。从与 PHP 的长期关系切换 =)
    • 好的,我认为这解决了它:gem "bson_ext"。谢谢!
    • 在您的 gemfile 中添加行 gem "bson_ext",然后从您的命令行运行 bundle update
    • 是的,你明白了。你可以像@theTRON 提到的那样运行bundle update,或者bundle install
    猜你喜欢
    • 2013-04-10
    • 1970-01-01
    • 2021-04-05
    • 1970-01-01
    • 1970-01-01
    • 2020-02-01
    • 2011-05-06
    • 2018-12-23
    • 2012-07-08
    相关资源
    最近更新 更多