Rails: Won’t Someone Think of the Children?
By chris on June 24th 2008 in /dev/rails, /dev/ruby | 589 views
I have a class, it acts_as_tree. I want to be able to delete nodes from the tree and heal the rift between grandparent and children, joining them as parent-child afterwards.
Seems like it should be pretty obvious but nothing I was coming up with was doing the trick. The node was always deleting yet so were its children. Then I googled upon this forum and the solution was found. When executing a before_destroy filter on a class that acts_as_tree, put the before filter first:
class VettingStage < ActiveRecord::Base before_destroy :extract_self_from_chain acts_as_tree :foreign_key => “parent_id”, :order => “name” … end
That was easy.
