Ruby on rails 3 Mongomapper:嵌入的文档无法正常工作

Ruby on rails 3 Mongomapper:嵌入的文档无法正常工作,ruby-on-rails-3,mongomapper,Ruby On Rails 3,Mongomapper,我不知道发生了什么,但我似乎找不到一段非常小的代码。我使用了没有嵌入文档的MongoMapper,一切都很顺利。我用一个嵌入的文档击中了砖墙。使用Rails控制台时,我将按照上的说明进行操作: 以下是我的模型: class Assessment include Mongomapper::Document many :sections end class Section include MongoMapper::EmbeddedDocument key :title, Strin

我不知道发生了什么,但我似乎找不到一段非常小的代码。我使用了没有嵌入文档的MongoMapper,一切都很顺利。我用一个嵌入的文档击中了砖墙。使用Rails控制台时,我将按照上的说明进行操作:

以下是我的模型:

class Assessment
  include Mongomapper::Document
  many :sections
end

class Section
  include MongoMapper::EmbeddedDocument
  key :title, String
  validates_presence_of :title
end
当我跑步时:
a=Assessment.create(:sections=>[Section.new(:title=>'test'))

我将获得以下输出:

=>#

我还尝试了
a=Assessment.new()
a.sections“test”)

但结果是一样的

为什么部分中没有内容?

包括:

attr_accessible :sections
应该使创建工作(在它为我做)。您可能需要添加:

validates_associated :sections
让您的评估以您可能期望的方式验证嵌入的部分


是的,晚了几年,但我不得不解决这个问题,谷歌把我带到了这里。

什么版本的Mongo?什么版本的MongoMapper?我认为MongoMapper和Mongo2.0还不能很好地配合。请看:我检查了我的版本,运行的是mongodb 2.0.0、mongomapper 0.9.2、Rails 3.0.10、Ruby 1.9.2p290。我卸载了mongo并安装了1.8.3版。我得到了同样的错误。我想我只是对数据的显示方式感到困惑。mm 0.9.1不打印
节:nil
,但0.9.2会打印,即使里面有节…耶,可能是0.9.2的东西,可能与