Square wheel*

Deprecating sliding_sessions

by pstradomski at 2009-02-18 18:13

As Alberto pointed out in one of the posts on my old wordpress blog, my sliding_sessions plugin will not work with Rails 2.3.

After short investigation it turns out the plugin is now completely obsolete and replaced with functionality in Rails itself.

If you need to set expiration period for sessions through all controllers in your application, simply add the following option to your config/intializers/session_store.rb file:

:expire_after => 60.minutes

If you need to set different expiration time in different controllers or actions, use the following code in action or some before_filter:

request.session_options = request.session_options.dup
request.session_options[:expire_after] = 5.minutes
request.session_options.freeze

Duplication of the hash is needed only because it is already frozen at that point, even though modification of at least :expire_after is possible and works flawlessly.

The old plugin (for Rails <= 2.2) is here: sliding_sessions.zip

Comments

James (not registered) at 2009-11-12 23:05: It seems that this functionality is broken as of 2.3.4. Here's a post from a discussion on the rails list that seems to explain the bug: http://groups.google.com/group/rubyonrails-talk/msg/b2ba91b16a10fd0d

pstradomski at 2009-11-12 23:31: Well, that's a pity. Alas, I'm not doing any Rails development for over a year now so there is not much I can do for you.

James (not registered) at 2009-11-13 00:10: Oh, yea. No worries. I posted here so that the next person who tries to use this piece of advice doesn't get as frustrated as I did today trying to figure out what's going on.

pstradomski at 2009-11-13 00:24: Sure. Thanks for the information.

Dan (not registered) at 2009-11-13 03:11: Heh James it appears we are looking for this info almost simultaneously :)

Add comment