Last Updated: February 25, 2016
·
3.588K
· kubabogaczewicz

Removing has_many links via ActiveAdmin

If you have a resource that has_many of something and you want to manage it all via ActiveAdmin, you will end up with form code like this:

form do |f|
  f.inputs "Details" do
    f.input :name
    # ...
  end

  f.has_many :links do |app_f|
    app_f.inputs do
      if !app_f.object.nil?
        app_f.input :_destroy, :as => :boolean, :label => "Destroy?"
      end

      app_f.input :name 
      # ...
    end
  end
  f.buttons
end

If selecting Destroy checkbox does nothing, just silently fails make sure you have :allowdestory enabled in your model's *acceptsnestedattributesfor*

class Gift < ActiveRecord::Base
  attr_accessible :description, :name, :price, :reserved, :links_attributes

  has_many :links, :dependent => :destroy

  accepts_nested_attributes_for :links, allow_destroy: true
end

1 Response
Add your response

Anybody know why this would work for a long time for me, and then suddenly stop working? Specifically, in the active_admin form, the "Add New Link" button does nothing when clicked. It used to work.

over 1 year ago ·