gpt4 book ai didi

ruby-on-rails - Rails admin以has_many嵌套形式隐藏hide_to字段

转载 作者:行者123 更新时间:2023-12-04 13:23:16 24 4
gpt4 key购买 nike

我有两个模型

class Entity < ActiveRecord::Base
# Associations
has_many :contacts
accepts_nested_attributes_for :contacts, :allow_destroy => true
end

class Contact < ActiveRecord::Base
# Associations
belongs_to :entity
end

现在在rails admin中,我得到以下选项。

添加新的联系表



添加新的实体表单

我需要在添加新实体的同时在联系表单中隐藏实体字段。

任何帮助将是有用的。

最佳答案

您可以像这样使用inverse_of自动隐藏字段

class Entity < ActiveRecord::Base
# Associations
has_many :contacts, inverse_of: :entity
accepts_nested_attributes_for :contacts, allow_destroy: true
end

class Contact < ActiveRecord::Base
# Associations
belongs_to :entity, inverse_of: :contacts
end

If you set the :inverse_of option on your relations, RailsAdmin will automatically populate the inverse relationship in the modal creation window. (link next to :belongs_to and :has_many multi-select widgets)



资料来源: https://github.com/sferik/rails_admin/wiki/Associations-basics

让我知道怎么回事

关于ruby-on-rails - Rails admin以has_many嵌套形式隐藏hide_to字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19271991/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com