# Acts\_as\_nested\_set, delete(node) method?

**URL:** <https://www.ruby-forum.com/t/acts-as-nested-set-delete-node-method/182452>\
**Category:** Rails\
**Created:** [January 28, 2010, 9:56am UTC](https://www.ruby-forum.com/t/acts-as-nested-set-delete-node-method/182452 "2010-01-28T09:56:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sushi2k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@sushi2k](https://www.ruby-forum.com/u/sushi2k)\
**Post date:** [January 28, 2010, 9:56am UTC](https://www.ruby-forum.com/t/acts-as-nested-set-delete-node-method/182452/1 "2010-01-28T09:56:28Z")

</div>

Hello,  
I’m using acts\_as\_nested\_set, and I can create root-nodes and add childs  
to it. No problem. But what can I do, to delete a certain node and all  
of it’s children? And of course in a way that it’s consistent, this  
means that the lft/rgt structure is still consistent.  
I’m using awesome nested set, but I can’t find a method that is doing  
this. Or am I blind?  
At least I couldn’t find it here

[http://wiki.github.com/collectiveidea/awesome\_nested\_set/awesome-nested-set-cheat-sheet](http://wiki.github.com/collectiveidea/awesome_nested_set/awesome-nested-set-cheat-sheet)

Thx…

---

<div class="post-metadata">

**Author:** ![sushi2k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@sushi2k](https://www.ruby-forum.com/u/sushi2k)\
**Post date:** [January 28, 2010, 6:37pm UTC](https://www.ruby-forum.com/t/acts-as-nested-set-delete-node-method/182452/2 "2010-01-28T18:37:33Z")

</div>

> [http://wiki.github.com/collectiveidea/awesome\_nested\_set/awesome-nested-set-cheat-sheet](http://wiki.github.com/collectiveidea/awesome_nested_set/awesome-nested-set-cheat-sheet)  
> Just destroy the object like you would any other AR object.

Keep this in mind as well (an option to the acts\_as\_nested\_set call in  
your model).

- +:dependent+ - behavior for cascading destroy. If set to :destroy,  
all the  
# child objects are destroyed alongside this object by  
calling their destroy  
# method. If set to :delete\_all (default), all the child  
objects are deleted  
# without calling their destroy method.

---

<div class="post-metadata">

**Author:** ![sushi2k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@sushi2k](https://www.ruby-forum.com/u/sushi2k)\
**Post date:** [February 1, 2010, 4:41am UTC](https://www.ruby-forum.com/t/acts-as-nested-set-delete-node-method/182452/3 "2010-02-01T04:41:18Z")

</div>

Philip H. wrote:

> > [http://wiki.github.com/collectiveidea/awesome\_nested\_set/awesome-nested-set-cheat-sheet](http://wiki.github.com/collectiveidea/awesome_nested_set/awesome-nested-set-cheat-sheet)  
> > Just destroy the object like you would any other AR object.
> 
> Keep this in mind as well (an option to the acts\_as\_nested\_set call in  
> your model).
> 
> - +:dependent+ - behavior for cascading destroy. If set to :destroy,  
> all the  
> # child objects are destroyed alongside this object by  
> calling their destroy  
> # method. If set to :delete\_all (default), all the child  
> objects are deleted  
> # without calling their destroy method.

Ok, destroy is what I’m looking for. Thx 😉 I can now delete all the  
childs of a certain node in the database.  
Is it also possible, to delete certain nodes from a nested set, when the  
nested set is in an array? After an:

> > @project = Project.find(:all)

in the console, I have all my projects in @project. I just want to  
delete now certain nodes (like id 4 and 5 or just node 6). I need this,  
because I want to create certain views on the nested set. But the  
destroy should only be done in this variable, not in the database.

> > @project.destroy(5)  
> > NoMethodError: undefined method `destroy’ for #Array:0x4eef268  
> > from (irb):11  
> > from :0

Even find does not work:

> > @project.find(5)  
> > LocalJumpError: no block given  
> > from (irb):8:in `find' from (irb):8:in `each’  
> > from (irb):8:in `find’  
> > from (irb):8  
> > from :0
