Thursday, March 19, 2009

Manually Accessing Sessions in Rails 2.3

Due to some limitations with the Google Earth browser plugin, I'm forced to manually access my Rails session to retrieve data that is used in a dynamic KML file. Previously, in Rails 2.2, I did something like this to access my ActiveRecord-based session:


CGI::Session::ActiveRecordStore::Session.find_by_session_id(id)


In Rails 2.3, this doesn't work any more and you are presented an error of the form:


uninitialized constant CGI::Session


To fix this, I found this post, which notes to use


ActionController::Session.find_by_session_id(id)


instead. However, per the Rails API docs, that only works for CookieStore, AbstractStore, and MemCacheStore. If you are using ActiveRecord for your stores like I am, this syntax instead is:


ActiveRecord::SessionStore::Session.find_by_session_id(id)

No comments: