fcheung edited this page Sep 12, 2010 · 3 revisions
Clone this wiki locally

== SmartSessionStore

A session store that avoids the pitfalls usually associated with concurrent access to the session (see the blog post for details)

Derived from Stefan Kaes’ SqlSessionStore

== Step 1

Generate your sessions table using rake db:sessions:create

== Step 2

Add the code below after the initializer config section:

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS. update(:database_manager => SmartSessionStore)

Finally, depending on your database type, add

SmartSessionStore.session_class = MysqlSession


SmartSessionStore.session_class = PostgresqlSession

SmartSessionStore.session_class = OracleSession

after the initializer section in environment.rb

== Step 3 (optional)

If you want to use a database separate from your default one to store
your sessions, specify a configuration in your database.yml file (say
sessions), and establish the connection on SqlSession in

SqlSession.establish_connection :sessions


1. You will need the binary drivers for Mysql or Postgresql.
These have been verified to work:

  • ruby-postgres ( with postgreql 8.1
  • ruby-mysql 2.7.1 with Mysql 4.1
  • ruby-mysql 2.7.2 with Mysql 5.0

2. Tests have been done with SqlLiteSession, SqlSession and MysqlSession. I don’t have access to Oracle or Postgresql and so have not been able to test those. Feedback would be very much appreciated