# Persisting tree navigation

**URL:** <https://www.ruby-forum.com/t/persisting-tree-navigation/100939>\
**Category:** Rails\
**Created:** [August 2, 2006, 12:06am UTC](https://www.ruby-forum.com/t/persisting-tree-navigation/100939 "2006-08-02T00:06:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [August 2, 2006, 12:06am UTC](https://www.ruby-forum.com/t/persisting-tree-navigation/100939/1 "2006-08-02T00:06:50Z")

</div>

I have built a tree navigation for pages I have in a site, that loads  
the content of each page into FCK editor. The parent nodes are shown at  
the beginning, and the child nodes are in display:none hidden divs that  
are toggled with scriptaculous bindup and binddown. If the user clicks  
on one of the children, I want that div to remain visible on page  
refresh. I’m pretty new with app programming, and I’m not sure how to  
tackle this. I was thinking session, but I have a suspicion it might be  
easier? I’ve tried setting an @display variable inside the for child in  
parent.children loop for the style, but I couldn’t get it to set the  
value outside. The following is the code I have in the view:

\<% for parent in @parents %\>

```
<%= link_to(h(parent.name), :id => parent, :action => 'edit_page') 

```

%\>  
\<%= image\_tag(‘toggle’,:onclick =\>  
“Effect.Toggle(‘child#{parent.id}’,‘blind’);”)%\>

  
\<% for child in parent.children %\>  
»\<%= link\_to(child.name, :id =\> child.id, :action =\>  
‘edit\_page’) %\>  
\<%= link\_to ‘Destroy’, { :action =\> ‘destroy’, :id =\> child },  
:confirm =\> ‘Are you sure?’, :post =\> true %\>  
  
\<% end %\>  
»\<%= link\_to ‘new Child’, :action =\> ‘newChild’, :id =\> parent  
%\>  
  

\<% end %\>

and then this is in the controller:

def edit\_page  
tree\_navigation  
if params[:id]  
@page = Page.find(params[:id])  
else  
@page = Page.find(:first)  
end  
@text = @page.text  
if @text == nil  
@text = ‘enter some text’  
end  
render :action =\> ‘list’  
end

def tree\_navigation  
@pages = Page.find(:all)  
@parents = []  
for page in @pages  
@parents \<\< page if !page.parent  
end  
end
