0
三种模式:创建错误在轨更新嵌套属性
class Order < ActiveRecord::Base
belongs_to :product
belongs_to :sale
end
class Sale < ActiveRecord::Base
has_many :orders
accepts_nested_attributes_for :orders, :reject_if => :all_blank
end
class Product < ActiveRecord::Base
belongs_to :greenhouse
has_many :orders
end
首先产品。然后,可以使用一个产品进行订单。那么,我期望的是,这个销售中充满了许多订单。但是,在保存Sale时,它只会忽略附加的Orders。
我只在Sale创建Order时找到了示例,或者父对象创建了Child对象,但在这种情况下,子对象或Order已经创建,并且只需要分配或关联与新的销售。
如何将子对象与新的父对象关联?
你能告诉你哪里有错误吗? – dimakura