Persisting tree navigation

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs