Question

I have two Models

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

Now in rails admin I am getting below options.

Add new Contact Form

enter image description here


Add new Entity Form

enter image description here

I need to hide Entity field in contact form , while adding new entity.

Any help will be useful.

Was it helpful?

Solution

You can automatically hide the fields using inverse_of like this

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)

Source: https://github.com/sferik/rails_admin/wiki/Associations-basics

Let me know how it went

OTHER TIPS

For the sake of completness and because i had this problem too and solved it, if you want to you can configure a model when it is used inside a nested form just like you do with edit, update, create and nested

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

  rails_admin do
    nested do
      configure :entity do
        hide
      end
    end
  end

end

Visit the official wiki for more info

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top