ruby on rails - Why aren't my nested attributes being destroyed along with the parent? -
i have resume model has_many :skills, , skills model belongs_to :resume.
i nesting skills form inside resume form , it's creating record , relationship perfectly. when try destroy resume, associated skill not being destroyed along it.
here models:
# resume.rb class resume < activerecord::base has_many :skills belongs_to :user accepts_nested_attributes_for :skills, allow_destroy: true end # skill.rb class skill < activerecord::base belongs_to :resume end
here's strong params in resume_controller.rb
def resume_params params.require(:resume).permit(:user_id, :title, :summary, :job_title, skills_attributes [:skill_name, :_destroy]) end
as far can tell passing _destroy key properly. noticed people had _destroy checkboxes in form. want skills deleted when destroy entire resume. thanks!
all have specified can destroy skills on resume checkboxes mention seeing in examples. if want destroy skills associated when resume destroyed have adjust has_many
declaration.
has_many :skills, dependent: :destroy
Comments
Post a Comment