object_id_session 0

Posted by yrashk

I’ve developed a very simple plugin that allows to store ActiveRecord models over session using their IDs transparently.

So, for example, you are saving User in a session:

 
                session[:user] = User.find(1)
                session[:newuser] = User.new
 

After this, your session will look like this:

This plugin does not requires you to change your code. To get your object back, you should just ask session for it:

 
                session[:user]
 

and you’ll get User instance. object_id_session is responsible for conversions to be performed.

It is a very early version, its code isn’t perfect and there are probably some bugs, but it seems to pass some basic tests (which are written in RSpec, of course)

You can install this plugin from svn://verbdev.com/rubylibs/object_id_session/trunk

Why it could be useful? Well, I’ve just thought that it is quite stupid to pass big objects around session all the time, checking whether they are still available in the database each time, etc.

May be I’m just missing something and this kind of functionality is already implemented somewhere. In this case, just kill me, yeah! :)