Active admin has_many through delete union

I am currently creating an association as follows:

show do h3 project.title panel "Utilisateurs" do table_for project.roles do column "Prenom" do |role| role.user.firstname end column "Nom" do |role| role.user.lastname end column "email" do |role| role.user.email end column "Role" do |role| role.role_name.name end end end end # override default form form do |f| f.inputs "Details" do # Project fields f.input :title f.input :code end f.has_many :roles do |app_f| app_f.inputs do # if object has id we can destroy it if app_f.object.id app_f.input :_destroy, :as => :boolean, :label => "Supprimer l'utilisateur du projet" end app_f.input :user, :include_blank => false, :label_method => :to_label app_f.input :role_name, :include_blank => false end end f.buttons end 

I have the following associations:

Project

 has_many :roles, :dependent => :destroy has_many :users, :through => :role 

User

 has_many :roles, :dependent => :destroy has_many :projects, :through => :role 

Role

 belongs_to :user belongs_to :project belongs_to :role_name 

Rolename

 has_many :roles 

When I try to destroy user associations through my form, nothing happens, any idea to solve this? Or add a delete link to my show block?

+7
source share
2 answers

Try adding accepts_nested_attributes_for to your project model (and roles_attributes to attr_accessible):

 class Project < ActiveRecord::Base has_many :roles, :dependent => :destroy has_many :users, :through => :role accepts_nested_attributes_for :roles, :allow_destroy => true attr_accessible :roles_attributes, (+ all you had here before) ... end 
+16
source

allow_destroy: true is the root of this problem.

+4
source

All Articles