Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Session Locking

Session Locking

SessionLocking

Extends module ActiveRecord for optional locking via session ID. The problem with locking records is that the user locking a record may never unlock it again.

An optimistic locking is built into Rails and solves the problem in not really locking but looking at a version: If a new version was written, the data is stale.

This module implements an alternative way by locking with a reference to the session table. This way the lock is removed at least if the session dies.

Constraint: The sessions have to be implemented via database and with table “sessions” as described in “Webdevelopment with Rails”.

To support session locking, a table has to provide column “lock_session” as foreign key to the sessions table.

Here a sample for a table:

create table foos { id int primary key, }

lock_session character varying(256) default null,
constraint fk_places_sessions foreign key (lock_session)
  references sessions (session_id) on delete set null

Here a sample on how to work with session locking:

foo = Foo.find_first

foo.locked_by_session?(session) => false

foo.lock_by_session(session) [...] foo.unlock_by_session(session)

NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly

Users


See all details


Membership

+ Join this railsplugin

Record Maintainer

'None'