2011-11-30 84 views
0

工作我有一个问题有一个非常简单的Gemfile:捆绑不mongo_ext

source :rubygems 
gem 'mongo' 
gem 'mongo_ext' 

我安装了宝石“包安装”,但它不会加载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扩展。

+1

您是否试过'gem install bson_ext',因为它建议? –

+0

我已安装它。当我使用'irb'时,它在我需要'mongo'时加载,但是当我使用'mongo exec ruil'时,它不会被加载。 –

回答

2

您需要BSON和bson_ext添加到您的Gemfile:

source :rubygems 
gem 'mongo' 
gem 'mongo_ext' 
gem 'bson' 
gem 'bson_ext' 

而一般来说,它是指定要使用的宝石的版本是个好主意。这样,即使宝石发生重大更改(或添加了影响您的新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'