views:

163

answers:

1

Hi All,

I'm looking for some non-javascript techniques by which to reload a page of tree items (basically divs within divs) while remembering their "show/hide" status. So far the only thing I can think of is to pass every entity's ID as part of a parameter list and have Rails then insert a "class-display" in the class list (or, of course, directly append the appropriate css) when the page reloads. In any case, is there a better way by which to manage these items?

Basically my goal is to be able to show/hide the tree whether JS is enabled or not.

Best.

A: 

I would seriously consider implementing this with cookies. It's not exactly critical data, as in the world isn't going to end if someone deletes a cookie and collapses their tree. It will also avoid having to spew state information all over your query strings.

When opening a new branch, your controller would add a new cookie that marks as "open" whatever div id needs to be expanded. Closing a branch would be the reverse -- controller deletes / modifies the cookie.

Then when rendering your view, use the cookie info to decide which divs should have their display style set to "normal" or "none".

jdl