我有两个型号
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
让我知道它是怎么回事