【发布时间】:2023-03-23 15:25:02
【问题描述】:
我的Pack 模型有行,这些行又包含项目,并且包和行都接受它们包含的集合的嵌套属性。
以下是模型:
Class Pack < ApplicationRecord
has_many :pack_lines, dependent: :destroy
accepts_nested_attributes_for :pack_lines, allow_destroy: true
end
Class PackLine < ApplicationRecord
belongs_to :pack
has_many :pack_line_items, dependent: :destroy
accepts_nested_attributes_for :pack_line_items, allow_destroy: true
end
Class PackLineItem < ApplicationRecord
belongs_to :pack_line
end
我花了很长时间才找到正确的语法来使用 permit 控制器中的嵌套嵌套参数。
【问题讨论】:
-
我最初是作为一个问题开始的,但我最终设法解决了我的问题,所以我发布了结果。而库马尔的回复,其实展示了一个更简单的方法。问题是:“我如何允许已经嵌套的对象的嵌套参数?”
标签: ruby-on-rails nested-attributes strong-parameters