Sam Joseph
2005-Oct-01 01:16 UTC
[Rails-spinoffs] storing state in cookies using scriptaculous
Hi All, So I''m using scriptaculous in rails to allow opening and closing of messages in a threaded forum without the need for reloading the entire page. What I was wondering was if there was some way to store the state (which messages are open and which are closed) in a cookie or something, so that when the user does reload the page the messages won''t all be reset to their initial closed state. I know it can be done in principal, but I was wondering if there was a clean or recommended way to achieve this in scriptacukous. Of course one approach is to store all the open/close state data in the db, but that''s specific to each user, and seems like a lot of work, and not necessarily something that we want to persist beyond an individual session. Many thanks in advance. CHEERS> SAM
Alan Gutierrez
2005-Oct-01 02:24 UTC
[Rails-spinoffs] storing state in cookies using scriptaculous
* Sam Joseph <gaijin@yha.att.ne.jp> [2005-10-01 00:40]:> Hi All, > > So I''m using scriptaculous in rails to allow opening and closing of > messages in a threaded forum without the need for reloading the entire page. > > What I was wondering was if there was some way to store the state (which > messages are open and which are closed) in a cookie or something, so > that when the user does reload the page the messages won''t all be reset > to their initial closed state. > > I know it can be done in principal, but I was wondering if there was a > clean or recommended way to achieve this in scriptacukous.> Of course one approach is to store all the open/close state data in the > db, but that''s specific to each user, and seems like a lot of work, and > not necessarily something that we want to persist beyond an individual > session.> Many thanks in advance.http://www.webreference.com/javascript/961125/index.html If you can flatten your cookie into name value pairs, then I''d store it as a url encoded string. I''d set the path to point to the path of the forums, to keep the other sections of your site free of unwanted cookies. If here are multiple forums... http://acme.com/forums/rockets.html http://acme.com/forums/anvils.html I''d name the cookie anvils or rockets, so you''d have just the forum information you need (rather than trying to build a tree within the cookie). Cookies have some fixed on some browsers. Cheers. -- Alan Gutierrez - alan@engrm.com - http://engrm.com/blogometer/
Sam Joseph
2005-Oct-04 02:15 UTC
[Rails-spinoffs] storing state in cookies using scriptaculous
Hi Alan, Thanks for all the tips - very helpful. However none of this is specific to scriptaculous right? You''re suggesting I write my own javascript to manipulate the cookies - which implies there is no cookie manipulation as part of scriptaculous and prototype? I checked out the prototype documentation http://wiki.script.aculo.us/scriptaculous/show/Prototype and couldn''t see any mention of cookies, and scriptaculous reference documentation appears to be a todo, so I guess rolling my own is the only way to go here ... CHEERS> SAM Alan Gutierrez wrote:>* Sam Joseph <gaijin@yha.att.ne.jp> [2005-10-01 00:40]: > > >>Hi All, >> >>So I''m using scriptaculous in rails to allow opening and closing of >>messages in a threaded forum without the need for reloading the entire page. >> >>What I was wondering was if there was some way to store the state (which >>messages are open and which are closed) in a cookie or something, so >>that when the user does reload the page the messages won''t all be reset >>to their initial closed state. >> > http://www.webreference.com/javascript/961125/index.html > > If you can flatten your cookie into name value pairs, then I''d > store it as a url encoded string. I''d set the path to point to > the path of the forums, to keep the other sections of your site > free of unwanted cookies. If here are multiple forums... > > http://acme.com/forums/rockets.html > http://acme.com/forums/anvils.html > > I''d name the cookie anvils or rockets, so you''d have just the > forum information you need (rather than trying to build a tree > within the cookie). > > Cookies have some fixed on some browsers. > > Cheers. > >-- >Alan Gutierrez - alan@engrm.com - http://engrm.com/blogometer/ >_______________________________________________ >Rails-spinoffs mailing list >Rails-spinoffs@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > >
Alan Gutierrez
2005-Oct-04 05:17 UTC
[Rails-spinoffs] storing state in cookies using scriptaculous
* Sam Joseph <gaijin@yha.att.ne.jp> [2005-10-04 01:48]:> Hi Alan, > > Thanks for all the tips - very helpful. > > However none of this is specific to scriptaculous right? You''re > suggesting I write my own javascript to manipulate the cookies - which > implies there is no cookie manipulation as part of scriptaculous and > prototype? > > I checked out the prototype documentation > http://wiki.script.aculo.us/scriptaculous/show/Prototype and couldn''t > see any mention of cookies, and scriptaculous reference documentation > appears to be a todo, so I guess rolling my own is the only way to go > here ...I wouldn''t look at it that way. The cigarettes are there. They are just in a different carton. Cookies in JavaScript are well defined, the work the same on all browsers, they are very old part of the environment. I don''t see how creating a wrapper class helps much, but maybe it''s a matter of familiarity, documentation. I''d be concerned about bloat. -- Alan Gutierrez - alan@engrm.com - http://engrm.com/blogometer/