Ruby on rails 更新rails中的嵌套属性时出错

Ruby on rails 更新rails中的嵌套属性时出错,ruby-on-rails,ruby-on-rails-4,nested-attributes,nested-form-for,Ruby On Rails,Ruby On Rails 4,Nested Attributes,Nested Form For,三种模式: 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::B

三种模式:

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
首先创建一个产品。然后,就可以用一种产品下订单。然后,我期望的是,销售充满了许多订单。但是,在保存销售时,它只会忽略随附的订单

我只找到了销售创建订单或父对象创建子对象的示例,但在本例中,子对象或订单已经创建,并且只需要分配或与新销售相关


如何将子对象与新的父对象关联?

请确保您的SalesController中有类似以下内容的许可参数:

params.require(:sale).permit(:each, :sale, :field, :as, :symbol, :and, orders_attributes: [:each, :order, :field, :as, :symbol])

这是给出所描述行为的最常见问题。如果没有,我们需要更多的信息。

您能显示错误所在的代码吗?