Acts_as_tree - how do I let the user create subnodes?

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

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.

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