gpt4 book ai didi

mongoid - 嵌套表单,嵌入式文档,Mongoid 2.2.0问题

转载 作者:行者123 更新时间:2023-12-01 14:19:04 28 4
gpt4 key购买 nike

我似乎无法在这里或通过Google找到答案,任何帮助都很棒。
建筑物可以正确保存,但是嵌入式文档PriorityArea不会更新...
我想最终让它均匀地为新的优先级区域添加一个新表格,但是需要首先对其进行更新。
BuildingsController#update中的Mongoid::Errors::InvalidFind
调用Document#find为nil无效

class Building
include Mongoid::Document
embeds_many :priority_areas
accepts_nested_attributes_for :priority_areas, :allow_destroy => true, :autosave => true
end

class PriorityArea
include Mongoid::Document
embedded_in :building, :inverse_of => :priority_areas
end
#view
= form_for [@customer, @building] do |f|
...
...
= f.fields_for :priority_areas do |pa|
= f.name
...
...
#controller
@building.update_attributes(params[:building])
它可以正确地从数据库中获取正确的数据,但是无法在建筑#update上出错。任何帮助是极大的赞赏。

更新
在建筑物中#update im
放置params [:building] [:priority_areas_attributes] .to_yaml
哪个屈服
--- !map:ActiveSupport::HashWithIndifferentAccess 
"0": !map:ActiveSupport::HashWithIndifferentAccess
name: area 51
location: near front door
notes: ""
priority: "1"
id: ""
"1": !map:ActiveSupport::HashWithIndifferentAccess
name: area 52
location: near rear door
notes: ""
priority: "2"
id: ""
我猜问题出在null ID:“”

最佳答案

问题是空ID
它需要有一个ObjectId才能正常工作。我的愚蠢错误。

关于mongoid - 嵌套表单,嵌入式文档,Mongoid 2.2.0问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7392766/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com