我遇到一个非常简单的Gemfile问题:
source :rubygems
gem 'mongo'
gem 'mongo_ext'
我使用“bundle install”安装了gem,但它没有加载mongo_ext。
irb(main):001:0> require 'rubygems'
=> false
irb(main):002:0> require 'mongo'
**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.
=> true
但是如果我使用系统irb我就是加载:
$ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'mongo'
=> true
irb(main):003:0>
也许这种行为是因为mongo_ext包含C扩展名。
答案 0 :(得分:2)
您需要将bson和bson_ext添加到您的Gemfile中:
source :rubygems
gem 'mongo'
gem 'mongo_ext'
gem 'bson'
gem 'bson_ext'
一般来说,指定您正在使用的宝石的版本是个好主意。这样,即使gem进行了重大更改(或添加了影响您的新bug),您也可以确保代码正常工作。指定启动项目时出现的最新版本,但只能小心升级它们。例如:
source :rubygems
gem 'mongo', '1.5.1'
gem 'mongo_ext', '0.19.3'
gem 'bson', '1.5.1'
gem 'bson_ext', '1.5.1'