活跃的管理员 - 为 Parent 和 has_many Children 编辑表单

active admin - editing form for Parent with has_many Children

我有 parent 有很多 children 关系。我想轻松管理特定 parent 的 children。

我正在这样尝试:

form do |f|
  f.inputs "Parent" do
    f.input :name
  end

  f.inputs 'Children' do
    f.has_many :children, new_record: true do |c|
      c.input :name
    end
  end
  f.actions
end

但我得到:

未定义方法`new_record?'对于 nil:NilClass

我有 Rails 5. 有没有更好的方法来完成这项工作?允许用户管理 child objects 的最佳方式是什么?

f.has_many :children do |c|
  c.inputs "Children" do
    c.input :name 
    #repeat as necessary for all fields
  end
end

确保在你的父模型中有这个:

accepts_nested_attributes_for :children