Ste*_*vis 4 ruby-on-rails associations rails-admin
我正在我的一个网站上使用Rails Admin.到目前为止它很棒,但我无法弄清楚如何从编辑页面中删除相关对象.
示例:我有两个模型Property和PropertyImage.
class Property
has_many :property_images, :dependent => :destroy
end
class PropertyImage
belongs_to :property
end
Run Code Online (Sandbox Code Playgroud)
我可以转到任一模型的实例的编辑屏幕,我可以从列表视图中删除PropertyImages.但是当我编辑一个Property时,我希望能够删除与它关联的PropertyImage.有没有办法在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
Run Code Online (Sandbox Code Playgroud)
包含该:allow_destroy
选项应该使嵌套项显示删除选项.