# Acts\_as\_tree - how do I let the user create subnodes?

**URL:** <https://www.ruby-forum.com/t/acts-as-tree-how-do-i-let-the-user-create-subnodes/91525>\
**Category:** Rails\
**Created:** [April 10, 2007, 3:04am UTC](https://www.ruby-forum.com/t/acts-as-tree-how-do-i-let-the-user-create-subnodes/91525 "2007-04-10T03:04:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@alex](https://www.ruby-forum.com/u/alex)\
**Post date:** [April 10, 2007, 3:04am UTC](https://www.ruby-forum.com/t/acts-as-tree-how-do-i-let-the-user-create-subnodes/91525/1 "2007-04-10T03:04:16Z")

</div>

Hi,

Noob here, so apologies in advance for my certain misunderstandings.

I have hierarchal category structure which I’ve modeled using  
acts\_as\_trees. I have successfully created the code to display the  
categories in a tree-ish fashion (it was very easy - I’m impressed).  
I would like to let users add new subcategories to an existing  
category by clicking on a “new subcategory” link next to each category  
name in this tree. I am having problems doing this.

My approach has been:

In the href of the “new subcategory” html, I stick the id of the  
parent like this:

[ 

I can pick up the parent\_id in the new action controller easily  
enough:  
@category = Category.new  
@category.parent = Category.find(params[:parent\_id])

 

But I loose it when I get to the create action controller, as the form  
does not have the parent\_id (nor do I want it to).

 

The I guess my basic issue is that I set up the parent that I want to  
use in the list rendering, but I can’t pass it all the way through to  
the create action.

 

Any suggestions?

 

Thanks,  
Alex

](https://www.ruby-forum.com/categories/new?parent_id=1)

---

<div class="post-metadata">

**Author:** ![alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@alex](https://www.ruby-forum.com/u/alex)\
**Post date:** [April 10, 2007, 11:58am UTC](https://www.ruby-forum.com/t/acts-as-tree-how-do-i-let-the-user-create-subnodes/91525/2 "2007-04-10T11:58:15Z")

</div>

the common method for cases like this is to save the parent\_id in a  
hidden field in the form.  
Or save it in the session.  
Or put it as a parameter in URL that the the form is calling.

---

<div class="post-metadata">

**Author:** ![alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@alex](https://www.ruby-forum.com/u/alex)\
**Post date:** [April 11, 2007, 3:52am UTC](https://www.ruby-forum.com/t/acts-as-tree-how-do-i-let-the-user-create-subnodes/91525/3 "2007-04-11T03:52:38Z")

</div>

Ok, thanks. I’ll give the hidden field method a try.
