Seoman Seoman - 4 years ago 127
Ruby Question

activeadmin: adding delete for a nested resource

I have a infrastructure object composed for many datacenters. In the apps/admin/infrastructures.rb I have the following code:

form do |f|
f.inputs "Infrastructure details" do
f.input :name

f.has_many :datacenters do |datacenter_form|
datacenter_form.input :name
end
end
f.buttons
end


I can add datacenters with no problems but I don't know how I can delete it from infrastructure form.

Answer Source

Solved adding the following line:

datacenter_form.input :_destroy, :as => :boolean, :required => false, :label => 'Remove'

The code looks like:

form do |f|
  f.inputs "Infrastructure details" do
    f.input :name

    f.has_many :datacenters do |datacenter_form|
      datacenter_form.input :name
      datacenter_form.input :_destroy, :as => :boolean, :required => false, :label => 'Remove'
    end
  end
  f.buttons
end
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download