MongoId和bson_ext问题:没有这样的文件要加载--bson_ext

时间:2010-07-15 10:08:26

标签: ruby-on-rails mongodb mongoid

关于'bson_ext'有一个类似的问题,但它对我不起作用。

MongoMapper and bson_ext problem

我正在使用Rails 2.3.8 + MongoId 1.9.1。我按照“installation”页面进行了操作:

gem install mongoid
gem install mongo -v=1.0.4
gem install bson_ext -v=1.0.4

在我的config / environment.rb中,我添加了:

config.gem 'mongoid'
config.gem 'mongo', :version=>'1.0.4'
config.gem 'bson_ext', :verstion=>'1.0.4'

当我使用ruby script/server启动应用程序时,它会显示:

=> Booting WEBrick
=> Rails 2.3.8 application starting on http://0.0.0.0:3000
no such file to load -- bson_ext
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in `require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:in `new_constants_in'
...
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
script/server:3
Missing these required gems:
  bson_ext  = 1.0.4

You're running:
  ruby 1.8.7.299 at /usr/local/bin/ruby
  rubygems 1.3.7 at /root/.gem/ruby/1.8, /usr/local/lib/ruby/gems/1.8

Run `rake gems:install` to install the missing gems.

但我安装了bson_ext 1.0.4

gem list

bson (1.0.4, 1.0.3, 1.0.1, 1.0)
bson_ext (1.0.4, 1.0.1, 1.0)
mongo (1.0.4, 1.0.1, 1.0)
mongoid (1.9.1)
mongo_ext (0.19.3)

并且,我尝试使用1.0和1.0.1,但抛出相同的异常。

怎么了?

2 个答案:

答案 0 :(得分:2)

尝试将config.gem行更改为:

config.gem 'bson_ext', :version=>'1.0.4', :lib => false

这可以防止rails试图要求“bson_ext”,这不起作用。 bson gem实际上会自动尝试“bson_ext / cbson”,如果找不到本机版本,最终会回到bson_ruby。

答案 1 :(得分:0)

我必须卸载所有bson和mongo宝石,然后只运行rake gems:install

  config.gem "mongo_mapper"

在我的environment.rb文件中。 MongoDB and MongoMapper的Railscasts帮助我开始使用我的Rails 2.3.8应用程序使用MongoDB。其他任何东西都会产生bson_ext错误。