These implement the same interface as the other CGI::Session stores, so they are
drop-in replacements. We will examine each one in detail here.
ActiveRecordStore
As its name suggests, the ActiveRecordStore is designed to store sessions in a database
via ActiveRecord. However, it is flexible, and does not strictly require
ActiveRecord. The standard usage of ActiveRecordStore is very simple if you are
already using ActiveRecord??”just set the session store in config/environment.rb:
config.action_controller.session_store = :active_record_store
A Rake task is provided to create the database migration for the sessions table: rake
db:sessions:create. You do not need to create the ActiveRecord Session class, as the
ActiveRecordStore sets one up for you. This class is called CGI::Session::
ActiveRecordStore::Session, so you can poke around its internals if you need to
change anything:
CGI::Session::ActiveRecordStore::Session.table_name = 'web_sessions'
The ActiveRecordStore uses few features of ActiveRecord, so it will actually work
with classes that act like ActiveRecord. This is useful if you are not otherwise using
* Standard library documentation is available at http://www.ruby-doc.org/stdlib/.
Architectural Scalability | 175
ActiveRecord, or if you are tuning performance and ActiveRecord??™s advanced features
are too heavy.
One such example, SqlBypass, is provided for you.
Pages:
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272