我正在使用带有 rails 3.2.3 的 mongoid 3.0。
mongoid.yml 看起来像:
development:
sessions:
default:
database: dana-x
hosts: localhost
服务器运行没有问题。但是当我尝试执行以下代码时:
User.where(:login => user_name).first
服务器返回 NoMethod 错误:
undefined method `map' for "localhost":String
.bundle/ruby/1.9.1/gems/moped-1.0.0.beta/lib/moped/cluster.rb:20:in `initialize'
.bundle/ruby/1.9.1/gems/moped-1.0.0.beta/lib/moped/session.rb:52:in `new'
.bundle/ruby/1.9.1/gems/moped-1.0.0.beta/lib/moped/session.rb:52:in `initialize'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/mongoid/sessions/factory.rb:60:in `new'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/mongoid/sessions/factory.rb:60:in `create_session'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/mongoid/sessions/factory.rb:41:in `default'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/mongoid/sessions.rb:109:in `default'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/mongoid/sessions.rb:354:in `__session__'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/mongoid/sessions.rb:199:in `mongo_session'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/mongoid/sessions.rb:157:in `collection'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/mongoid/contextual/mongo.rb:208:in `initialize'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/mongoid/contextual.rb:47:in `new'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/mongoid/contextual.rb:47:in `create_context'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/mongoid/contextual.rb:30:in `context'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/mongoid/contextual.rb:20:in `rescue in first'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/mongoid/contextual.rb:18:in `first'
app/controllers/feed_controller.rb:5:in `index'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/abstract_controller/base.rb:167:in `process_action'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal/rendering.rb:10:in `process_action'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
.bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:414:in `_run__980518159__process_action__502500855__callbacks'
.bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:405:in `__run_callback'
.bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
.bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/abstract_controller/callbacks.rb:17:in `process_action'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal/rescue.rb:29:in `process_action'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
.bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/notifications.rb:123:in `block in instrument'
.bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
.bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/notifications.rb:123:in `instrument'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/abstract_controller/base.rb:121:in `process'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/abstract_controller/rendering.rb:45:in `process'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal.rb:203:in `dispatch'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal.rb:246:in `block in action'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:73:in `call'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:36:in `call'
.bundle/ruby/1.9.1/gems/journey-1.0.3/lib/journey/router.rb:68:in `block in call'
.bundle/ruby/1.9.1/gems/journey-1.0.3/lib/journey/router.rb:56:in `each'
.bundle/ruby/1.9.1/gems/journey-1.0.3/lib/journey/router.rb:56:in `call'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:600:in `call'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/rack/mongoid/middleware/identity_map.rb:33:in `block in call'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/mongoid/unit_of_work.rb:39:in `unit_of_work'
.bundle/ruby/1.9.1/bundler/gems/mongoid-cb1312e5385c/lib/rack/mongoid/middleware/identity_map.rb:33:in `call'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
.bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/etag.rb:23:in `call'
.bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/conditionalget.rb:25:in `call'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/head.rb:14:in `call'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/flash.rb:242:in `call'
.bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in `context'
.bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in `call'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/cookies.rb:338:in `call'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
.bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:405:in `_run__647823261__call__262699075__callbacks'
.bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:405:in `__run_callback'
.bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
.bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/reloader.rb:65:in `call'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
.bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/rack/logger.rb:26:in `call_app'
.bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/rack/logger.rb:16:in `call'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/request_id.rb:22:in `call'
.bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
.bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call'
.bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
.bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call'
.bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/static.rb:62:in `call'
.bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:479:in `call'
.bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/application.rb:220:in `call'
.bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/content_length.rb:14:in `call'
.bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/rack/log_tailer.rb:14:in `call'
.bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service'
/home/scepion1d/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/home/scepion1d/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/home/scepion1d/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
我认为这个问题与db有关。有谁知道如何解决这个问题?