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
Written by Kuba Bogaczewicz
Related protips
1 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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#