ActiveAdmin duplicates nested forms and the delete flag does not work

The form works to add elements to the model, but the elements are not deleted! Even worse, any update duplicates all nested forms (1x2 = 2, then the next update is 4 for each, etc.).

application / 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

application / 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

application / models / project_feature.rb

class ProjectFeature < ActiveRecord::Base
    belongs_to :project

end

application / models / project_feature.rb

class ProjectMention < ActiveRecord::Base
    belongs_to :project

end
+4
source share
1 answer

Try :_destroyinstead :_destroy => trueto allow_params block.

Duplication: Delete the contents of your public folder. In development mode, you do not need to precompile the assets.

:, :

project_features_attributes: [:id, :project_id, :description, :_destroy],
project_mentions_attributes: [:id, :project_id, :title, :url, :published, :_destroy]
+6

All Articles