我是 Rails 开发的新手,我也开始使用 MongoDB。
我一直在关注这个关于 Rails 复杂表单的Railscast教程,但我使用 MongoDB 作为我的数据库。我在插入带有子项的文档并将数据检索到编辑表单时没有问题,但是当我尝试更新它时出现此错误
未定义的方法 `assert_valid_keys' for false:FalseClass
这是我的实体类
class Project
include MongoMapper::Document
key :name, String, :required => true
key :priority, Integer
many :tasks
after_update :save_tasks
def task_attributes=(task_attributes)
task_attributes.each do |attributes|
if attributes[:id].blank?
tasks.build(attributes)
else
task = tasks.detect { |t| t.id.to_s == attributes[:id].to_s }
task.attributes = attributes
end
end
end
def save_tasks
tasks.each do |t|
if t.should_destroy?
t.destroy
else
t.save(:validate => false)
end
end
结束结束
class Task
include MongoMapper::EmbeddedDocument
key :project_id, ObjectId
key :name, String
key :description, String
key :completed, Boolean
belongs_to :project
attr_accessor :should_destroy
def should_destroy?
should_destroy.to_i == 1
end
end
有谁知道这里发生了什么?谢谢