【发布时间】:2017-02-19 18:52:51
【问题描述】:
我有一个嵌入供应商的简单投标模型:
class Bid
include Mongoid::Document
field :amount, type: Integer
embeds_one :supplier
accepts_nested_attributes_for :supplier
end
许多投标有相同的供应商。如果我使用的是脚手架编辑视图,我将如何在更新方法中更新投标中嵌入供应商的所有实例?
我尝试过类似的方法,但没有成功
def update
@supplier.update(supplier_params)
#or
#bids = Bid.where('supplier._id' => @supplier.id)
#bids.supplier.update_attributes!(supplier_params)
redirect_to @supplier
end
【问题讨论】:
-
How would I update all of the instances of the embedded supplier in bids?是什么意思 - 这个问题没有意义,因为您有embeds_one关系。因此,更新投标永远不会更新多个供应商。
标签: ruby-on-rails mongoid