MongoDB 下载 Bindiry 大大的 demo 把玩,尝试更改 Mongoid 版本到最新,出现如下错误,求教

bovvic · 2013年02月10日 · 最后由 mjf429 回复于 2013年02月12日 · 3354 次阅读

俺是菜鸟,很多不懂,多多指教

D:\Software\webapps\demo>rails server
=> Booting WEBrick
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/carrierwave/uplo
ader/configuration.rb:91:in `eval': cannot load such file -- mongo (LoadError)
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:240:in `block in require'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:223:in `block in load_dependency'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:640:in `new_constants_in'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:223:in `load_dependency'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:240:in `require'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/carrierwave-mongoid-0.1.0
/lib/carrierwave/storage/grid_fs.rb:2:in `<top (required)>'
        from (eval):1:in `storage'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/car
rierwave/uploader/configuration.rb:91:in `eval'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/car
rierwave/uploader/configuration.rb:91:in `storage'
        from D:/Software/webapps/demo/config/initializers/carrierwave.rb:2:in `b
lock in <top (required)>'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/car
rierwave/uploader/configuration.rb:118:in `configure'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/car
rierwave.rb:21:in `configure'
        from D:/Software/webapps/demo/config/initializers/carrierwave.rb:1:in `<
top (required)>'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:234:in `load'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:234:in `block in load'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:223:in `block in load_dependency'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:640:in `new_constants_in'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:223:in `load_dependency'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:234:in `load'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
engine.rb:556:in `block (2 levels) in <class:Engine>'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
engine.rb:555:in `each'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
engine.rb:555:in `block in <class:Engine>'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
initializable.rb:30:in `instance_exec'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
initializable.rb:30:in `run'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
initializable.rb:55:in `block in run_initializers'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
initializable.rb:54:in `each'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
initializable.rb:54:in `run_initializers'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
application.rb:96:in `initialize!'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
railtie/configurable.rb:30:in `method_missing'
        from D:/Software/webapps/demo/config/environment.rb:5:in `<top (required
)>'
        from D:/Software/webapps/demo/config.ru:3:in `require'
        from D:/Software/webapps/demo/config.ru:3:in `block in <main>'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/buil
der.rb:51:in `instance_eval'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/buil
der.rb:51:in `initialize'
        from D:/Software/webapps/demo/config.ru:in `new'
        from D:/Software/webapps/demo/config.ru:in `<main>'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/buil
der.rb:40:in `eval'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/buil
der.rb:40:in `parse_file'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/serv
er.rb:200:in `app'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
commands/server.rb:46:in `app'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/serv
er.rb:304:in `wrapped_app'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/serv
er.rb:254:in `start'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
commands/server.rb:70:in `start'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
commands.rb:54:in `block in <top (required)>'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
commands.rb:49:in `tap'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
commands.rb:49:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

从错误提示上看,应该是没有装 mongo,跟 mongoid 无关。

#1 楼 @lgn21st 嗯嗯,添加以后,接着变成如下错误


D:\Software\webapps\demo>rails s
=> Booting WEBrick
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
D:/Software/webapps/demo/config/initializers/carrierwave.rb:4:in `block in <top
(required)>': undefined method `database' for Mongoid:Module (NoMethodError)
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/car
rierwave/uploader/configuration.rb:118:in `configure'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/car
rierwave.rb:21:in `configure'
        from D:/Software/webapps/demo/config/initializers/carrierwave.rb:1:in `<
top (required)>'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:234:in `load'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:234:in `block in load'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:223:in `block in load_dependency'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:640:in `new_constants_in'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:223:in `load_dependency'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/a
ctive_support/dependencies.rb:234:in `load'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
engine.rb:556:in `block (2 levels) in <class:Engine>'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
engine.rb:555:in `each'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
engine.rb:555:in `block in <class:Engine>'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
initializable.rb:30:in `instance_exec'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
initializable.rb:30:in `run'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
initializable.rb:55:in `block in run_initializers'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
initializable.rb:54:in `each'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
initializable.rb:54:in `run_initializers'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
application.rb:96:in `initialize!'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
railtie/configurable.rb:30:in `method_missing'
        from D:/Software/webapps/demo/config/environment.rb:5:in `<top (required
)>'
        from D:/Software/webapps/demo/config.ru:3:in `require'
        from D:/Software/webapps/demo/config.ru:3:in `block in <main>'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/buil
der.rb:51:in `instance_eval'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/buil
der.rb:51:in `initialize'
        from D:/Software/webapps/demo/config.ru:in `new'
        from D:/Software/webapps/demo/config.ru:in `<main>'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/buil
der.rb:40:in `eval'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/buil
der.rb:40:in `parse_file'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/serv
er.rb:200:in `app'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
commands/server.rb:46:in `app'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/serv
er.rb:304:in `wrapped_app'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/serv
er.rb:254:in `start'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
commands/server.rb:70:in `start'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
commands.rb:54:in `block in <top (required)>'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
commands.rb:49:in `tap'
        from D:/Software/Ruby/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/
commands.rb:49:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

错误信息已经给你足够的线索了呀,检查一下 config/initializers/carrierwave.rb 嘛。

#3 楼 @lgn21st 俺是菜鸟~~😓



CarrierWave.configure do |config|
  config.storage = :grid_fs
  config.grid_fs_access_url = ""
  config.grid_fs_database = Mongoid.database.name
  config.grid_fs_host = Mongoid.config.master.connection.host
end


@lgn21st 你猜错了,^_^,这个问题我知道答案,他的 mongoid 升级到 3.0 以上了,carrierwave-mongoid 只支持 mongoid2.0,问题出在 mongoid3.0 不支持 gridfs,所以他有两个解决方案,一个是在 gemfile 里指定 mongoid 到 2.0+,还一个是不要用 carrierwave-mongoid,改:file 或者找个云盘吧,用:file 的话部署的时候记得挂载 NFS

#5 楼 @mjf429 完全不懂啊,大哥😭 :file???,,nfs????????

#6 楼 @bovvic 结论就是你的 mongoid 和 carrierwave 不匹配,你换个 2.1.xx 的 mongoid 就好了,在你的 gemfile 里,换完后需要改成 mongoid2 格式的 mongoid.yml

#6 楼 @bovvic 好好看看文档吧,看文档的时候看全一点https://github.com/jnicklas/carrierwave

#8 楼 @mjf429 😓我想保留 MongoID3 而舍弃 carrierwave,该怎么搞呢

carrierwave 很好啊,应该是两个都能保留的,carrierwave-mongoid 有个 3.0 的分支,我没试过,你可以试试看,https://github.com/jnicklas/carrierwave-mongoid/tree/mongoid-3.0

需要 登录 后方可回复, 如果你还没有账号请 注册新账号