Rails管理员 – 删除相关对象

我正在我的一个网站上使用Rails Admin 。 到目前为止它很棒,但我无法弄清楚如何从编辑页面中删除相关对象。

示例:我有两个模型Property和PropertyImage。

class Property has_many :property_images, :dependent => :destroy end class PropertyImage belongs_to :property end 

我可以在编辑屏幕上找到任一模型的实例,我可以从列表视图中删除PropertyImages。 但是当我编辑一个Property时,我希望能够删除与它关联的PropertyImage。 有没有办法在rails_admin中启用此function?

这是我能看到的。

rails_admin接口

注意:“删除图像”按钮不是我想要的 – 它只是因为有一个上传关联到图像字段。 它只编辑PropertyImage。

我有同样的问题,在找到你的问题后找到了一个适合我的答案。

为了从Property表单中正确设置PropertyImage的编辑,您可能希望指定它可以使用嵌套表单:

 # property.rb class Property has_many :property_images, :dependent => :destroy accepts_nested_attributes_for :property_images, :allow_destroy => true end 

包括:allow_destroy选项应该为嵌套项显示删除选项。

带有删除按钮的嵌套表单的屏幕截图