Ruby on rails Mongoid无法创建记录

Ruby on rails Mongoid无法创建记录,ruby-on-rails,mongoid,Ruby On Rails,Mongoid,我不确定我的设置有什么问题。。。我无法创建mongoid记录(使用mongoid 3.0.0): bundle exec rails控制台 ruby-1.9.2-p290 :045 > u = NoUser.new => #<NoUser _id: 4ffc2e8487bc11b128000005, _type: nil, username: nil> ruby-1.9.2-p290 :046 > u.username = 'aaa1' => "aa

我不确定我的设置有什么问题。。。我无法创建mongoid记录(使用mongoid 3.0.0):

bundle exec rails控制台

ruby-1.9.2-p290 :045 >   u = NoUser.new
 => #<NoUser _id: 4ffc2e8487bc11b128000005, _type: nil, username: nil> 
ruby-1.9.2-p290 :046 > u.username = 'aaa1'
 => "aaa1" 
ruby-1.9.2-p290 :047 > u
 => #<NoUser _id: 4ffc2e8487bc11b128000005, _type: nil, username: "aaa1"> 
ruby-1.9.2-p290 :048 > u.save
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
    gems/moped-1.1.1/lib/moped/node.rb:74:in `block in command'
    gems/moped-1.1.1/lib/moped/node.rb:522:in `[]'
    gems/moped-1.1.1/lib/moped/node.rb:522:in `block (3 levels) in flush'
    gems/moped-1.1.1/lib/moped/node.rb:521:in `map'
    gems/moped-1.1.1/lib/moped/node.rb:521:in `block (2 levels) in flush'
    gems/moped-1.1.1/lib/moped/node.rb:113:in `ensure_connected'
    gems/moped-1.1.1/lib/moped/node.rb:517:in `block in flush'
    gems/moped-1.1.1/lib/moped/node.rb:532:in `logging'
    gems/moped-1.1.1/lib/moped/node.rb:516:in `flush'
    gems/moped-1.1.1/lib/moped/node.rb:505:in `process'
    gems/moped-1.1.1/lib/moped/node.rb:70:in `command'
    gems/moped-1.1.1/lib/moped/node.rb:356:in `refresh'
    gems/moped-1.1.1/lib/moped/cluster.rb:101:in `block in refresh'
    gems/moped-1.1.1/lib/moped/cluster.rb:114:in `each'
    gems/moped-1.1.1/lib/moped/cluster.rb:114:in `refresh'
    gems/moped-1.1.1/lib/moped/cluster.rb:67:in `nodes'
... 9 levels...
    gems/activesupport-3.1.0/lib/active_support/callbacks.rb:81:in `run_callbacks'
    gems/mongoid-3.0.0/lib/mongoid/callbacks.rb:98:in `run_callbacks'
    gems/mongoid-3.0.0/lib/mongoid/persistence/insertion.rb:24:in `block in prepare'
    gems/activesupport-3.1.0/lib/active_support/callbacks.rb:390:in `_run_save_callbacks'
    gems/activesupport-3.1.0/lib/active_support/callbacks.rb:81:in `run_callbacks'
    gems/mongoid-3.0.0/lib/mongoid/callbacks.rb:98:in `run_callbacks'
    gems/mongoid-3.0.0/lib/mongoid/persistence/insertion.rb:23:in `prepare'
    gems/mongoid-3.0.0/lib/mongoid/persistence/operations/insert.rb:26:in `persist'
    gems/mongoid-3.0.0/lib/mongoid/persistence.rb:50:in `insert'
    gems/mongoid-3.0.0/lib/mongoid/persistence.rb:79:in `save'
    from (irb):48
    gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
    gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
    gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'ruby-1.9.2-p290 :049 > 
试一试

试一试


解决方案是从ruby 1.9.2升级到ruby 1.9.3。提示来自这样一个事实,即抛出错误的是
moped
gem。

解决方案是从ruby 1.9.2升级到ruby 1.9.3。提示来自于,事实上是
moped
gem抛出了错误。

嗯,我的模型怎么了?看起来是这样的,我保证!检查相同的操作是否适用于项目中的其他集合嗯,我的模型有什么问题吗?看起来是这样的,我保证!检查相同的操作是否适用于项目中的其他集合
class NoUser

  include Mongoid::Document

  field :username, :type => String
end
field :username, type: String