本文介绍了Rails的管理 - 删除相关对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的网站之一。这是伟大的,到目前为止,但我无法弄清楚如何从一个编辑页面中删除相关的对象。

I'm using Rails Admin on one of my sites. It's great so far, but I can't figure out how to remove a related object from an edit page.

例如:
我有两个型号财产和PropertyImage。

Example:I have two models Property and PropertyImage.

class Property
  has_many :property_images, :dependent => :destroy
end

class PropertyImage
  belongs_to :property
end

我可以去编辑屏幕无论是模型的实例,我可以删除他们的列表视图PropertyImages。但是,当我编辑属性,我希望能够删除与它相关的PropertyImage。有没有办法打开在rails_admin此功能?

I can go to the edit screen for an instance of either model, and I can delete PropertyImages from their list view. But when I edit a Property, I want to be able to delete a PropertyImage that's associated with it. Is there a way to turn on this functionality in rails_admin?

这是我可以看到。

请注意:删除图片按钮,是不是我要找的 - 它只是因为有一个上传关联像场。它只编辑PropertyImage。

Note: the "Delete Image" button isn't what I'm looking for - it's just because there's an upload association to the Image field. It only edits the PropertyImage.

推荐答案

我有同样的问题,并发现阅读您的问题后,对我的作品的答案。

I had this same question, and found an answer that works for me after reading your question.

为了正确设置了PropertyImage从所有制形式的编辑,你可能要指定它可以与嵌套形式工作:

In order to properly setup up the editing of PropertyImage from the Property form, you probably want to specify that it can work with the nested form:

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

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

Including the :allow_destroy option should make the delete option show up for the nested item.

这篇关于Rails的管理 - 删除相关对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 06:03