ruby on rails - accepts_nested_attributes_for :models, allow_destroy: true not working -


my params so:

"job" => {"title"=>"marketing head", "job_role_id"=>"13",    "challenge_assignments_attributes"=>{     "0"=>{"_destroy"=>"true", "challenge_id"=>"13", "id"=>"12"},      "1"=>{"_destroy"=>"true", "challenge_id"=>"13", "id"=>"13"}   }  } 

i have in job.rb
accepts_nested_attributes_for :challenge_assignments, reject_if: :all_blank, allow_destroy: true

and in job_controller.rb permit these challenge_assignments_attributes: [:id, :challenge_id, :_destroy]

yet on saving objects don't destroyed. have model set in same way , _destroy key works it. configuration both same yet 1 works , other doesn't.

are there other conditions under allow_destroy doesn't work cause i've tried @ source code no avail.

for i've made monkey patch remove objects myself. isn't best way go it.

challenge_assignments = job_params['challenge_assignments_attributes'] flag = false challenge_assignments.each |k,v|      if ['t', '1', 'true'].include? v['_destroy']        challengeassignment.find(v['id']).destroy        flag = true      end end flag ? jp = job_params.except!("challenge_assignments_attributes") : jp = job_params 

job.rb

class job < activerecord::base   has_many :challenge_assignments, dependent: :destroy   has_many :jobs, through: :challenge_assignments   has_many :challenge_assignments, dependent: :destroy   has_many :challenges, through: :challenge_assignments    accepts_nested_attributes_for :challenge_assignments, reject_if: :all_blank, allow_destroy: true   end 

after posting model code noticed had written duplicate has_many other side of join i'd copied on mistake. commenter brought attention it.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -