ruby-on-rails – Rails管理员以has_many嵌套形式隐藏belongs_to字段

我有两个型号
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管理员我得到以下选项.

添加新的联系表格

添加新的实体表单

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

任何帮助都会有用.

解决方法

您可以使用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 multiselect widgets)

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

让我知道它是怎么回事

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...