This may be obvious (either obviously simple or, on the other hand,
obviously a very hard problem), but I’m working on my first non-
trivial Rails app (well, web app in general for that matter) and I’m
running time and time again into the problem of managing client
On several pages, my app has some state that needs to be set at the
page level, but used to render the page and be used when AJAX code re-
renders parts of page (for instance, the app allows some fields to
manipulated with AJAX).
At first, I tried passing all the state through the links (i.e.
embedded the state in the URL), but this seemed both inefficient (I
have some reasonably large objects and we could only pass IDs through
the links, so I had to hit the DB again each time) and tricky to
manage - I found myself passing tons of state through links and it was
hard to manage it all.
So, I tried keeping it all on the server. It was efficient, much
easier to manage (I could set some state at the controller level, and
access it anywhere). Unfortunately, it has created some nasty bugs
(since I have to track down what weird state the app is in) and
doesn’t work when a user users the page in multiple windows/tabs
(since the state gets all mixed up between instances).
I’ve been reading up on REST as well as continuation-based servers
(which, from my limited understanding and very roughly speaking, very
intelligently store user state on the server), which leads me to
believe I should try one of the following strategies:
- Try to be as RESTful as possible and ditch all server-side state. I
think the best approach would be to have some object that encapsulates
all the data that needs to be encoded in the URLs and has helpers to
write URLs for me (i.e has specialized versions of link_to, etc).
- Keep the server-side state, but make it a lot smarter - able to
handle multiple tabs/windows from the same user simultaneously
How have others handed storing user state in their apps? Are there
strategies/gems/plugins/design patterns that people have used to
successfully implement option 1 or 2 above?