【发布时间】:2014-04-03 05:11:18
【问题描述】:
我不知道如何使用 Active Admin 中的嵌套资源输入助手来更新“父”记录的关联记录的值。
我试图为其生成更新的模型是这样的:
class Page < ActiveRecord::Base
has_many :page_attributes
accepts_nested_attributes_for :page_attributes, allow_destroy: true
end
其中PageAttribute有两个属性,:key和:value
ActiveAdmin 模型是:
ActiveAdmin.register Page do
permit_params page_attributes_attributes: [:key, :value, :_destroy => true]
form do |f|
f.inputs do
f.has_many :page_attributes, allow_destroy: true, heading: 'Parts' do |page_part|
page_part.input :key
page_part.input :value
end
end
f.actions
end
end
但是当我调用http://localhost:3000/admin/pages/2/edit 并更改现有属性的值时(或者当我选中删除复选框时),会发生一个新的PageAttribute 模型的记录和现有的关联保持不变。
我阅读了Active Admin documentation on nested resources 和一堆 SO 帖子,但不知道我做错了什么:(
【问题讨论】:
标签: ruby-on-rails activeadmin nested-attributes