Rails 4 - 多个嵌套表单

时间:2017-07-17 08:34:39

标签: ruby-on-rails ruby-on-rails-4 nested-forms form-for

我尝试创建一个与N个模型关联的嵌套表单。

这是架构:

schema

我需要一个Edit-Form,它遍历所有对象,直到最后一个:

enter image description here

我的投放对象如下所示:

class Delivery < ActiveRecord::Base
    has_many :boxes

这是框对象

class Box < ActiveRecord::Base

    belongs_to :box, :polymorphic => true, :inverse_of => :box
    has_many :boxes
    accepts_nested_attributes_for :boxes

1 个答案:

答案 0 :(得分:0)

在交货控制器中:

def new
  @delivery = Delivery.new
  # if you want 3 instantiated objects
  3.times { @delivery.boxes.build }
end
相关问题