I’d be very grateful for a code snippet showing off jQuery functionality remembering state, e.g. .slideToggle().
I’ve read about local storage, session storage, ajax among others – what technique is preferred 2012 and how could an implementation look like in Ruby on Rails 3.2?
There’s more than one way to do this. To store a variable in the url as a parameter (accessible from the params[] hash in rails), in your javascript you can write something like (example taken from this question )
If you want something a bit more durable, try a cookie. There is a cookies[] hash in Rails3 (not sure about rails2). The session[] hash is stored as a cookie by default as well. You can check out this railscast on making a “remember me” login function which used the cookies[] hash. Also see the docs on the Cookie class in Rails3, which gives a pretty good explanation of the various options and methods you have available.
With jQuery, you will apparently need a plugin as the functionality to read/write cookies with jQuery is not there automatically (I was surprised to find that). Here’s one on github that seems to be recommened and has some good documentation, though I haven’t used it: https://github.com/carhartl/jquery-cookie