The form works to add items to the Model but items are not deleting! Worse, any update duplicates all of the nested forms (1x2=2, then the next update makes 4 for each, etc.)
app/admin/project.rb
ActiveAdmin.register Project do
permit_params :title, :description, :git_url, :demo_url, :version, :lastpublished, :firstpublished,
project_features_attributes: [:project_id, :description, :_destroy => true],
project_mentions_attributes: [:project_id, :title, :url, :published, :_destroy => true]
form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs
f.buttons
end
form do |f|
f.inputs "Project Details" do
f.inputs :title
f.inputs :description
f.inputs :git_url, :default => "http://github.com/"
f.inputs :demo_url
f.inputs :version
f.inputs :firstpublished
f.inputs :lastpublished
f.inputs do
f.has_many :project_features,
:allow_destroy => true,
:heading => 'Features' do |cf|
cf.input :description
end
end
f.inputs do
f.has_many :project_mentions,
:allow_destroy => true,
:heading => 'Mentions' do |cf|
cf.input :title
cf.input :url
cf.input :published
end
end
end
f.actions
end
end
app/models/project.rb
class Project < ActiveRecord::Base
has_many :project_features, :dependent => :destroy
accepts_nested_attributes_for :project_features,
:reject_if => lambda{ |a| a[:description.blank?] },
:allow_destroy => true
has_many :project_mentions, :dependent => :destroy
accepts_nested_attributes_for :project_mentions,
:reject_if => lambda{ |a| a[:title.blank?] },
:allow_destroy => true
has_many :blogs
end
app/models/project_feature.rb
class ProjectFeature < ActiveRecord::Base
belongs_to :project
end
app/models/project_feature.rb
class ProjectMention < ActiveRecord::Base
belongs_to :project
end