我使用 ActiveAdmin 作为我的应用程序的后台,我有以下三个模型:
class Organization
has_many :organization_collection_relations
has_many :collections, through: :organization_collection_relations
end
class OrganizationCollectionRelation
belongs_to :organization
belongs_to :collection
after_destroy :do_something
end
class Collection
has_many :organization_collection_relations
has_many :organizations, through: :organization_collection_relations
end
在我的编辑页面中Organization
我有和f.input :collections
。当我编辑和组织时,例如删除所有集合,问题就出现了。这after_destroy
回调方法do_something
没有被触发。因此,我必须在活动管理文件的控制器部分中采取解决方法。
controller do
def update
resource = Organization.find(params[:id])
former_ids = resource.collection_ids
super
new_ids = resource.reload.collection_ids
# my logic here
end
end
我认为有更好的方法来处理这个问题......
Active Admin 也有自己的回调,因此您可以在管理文件夹中的organizations.rb 文件中使用如下所示的回调。
after_destroy do |organization|
# do your stuff
end
我之前为 before_save 和 after_save 完成了它,我不确定它是否可用于 after_destroy 你可以查看here https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/callbacks.rb有关主动管理回调的更多信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)