Switching to active_record_store session management errors out


#1

Hello,

Running Ruby 1.8.6 and Rails 2.2.2 against an Oracle XE database
(sigh).

I just upgraded Rails from 1.2.3 to 2.2.2, which made my cookie based
system for storing session information to error out due to the 4Kb
limit. So, I tried to turn on the active_record_store system by un-
commenting out the “config.action_controller.session_store
= :active_record_store” line in environment.rb and then create a db
session (db:sessions:create) and run a rake migration (rake
db:migrate).

Got all that done, which created a table named SESSIONS in the DB.
However I had to tweak the migration code because the table name
generated was singular (SESSION) and Oracle didn’t like that name. I
searched the internet and found a sample where the table name was
plural (SESSIONS), so I made the change hoping for the best. Here is
the SQL generated:

CREATE TABLE “SESSIONS”
( “ID” NUMBER(38,0) NOT NULL ENABLE,
“SESSION_ID” VARCHAR2(255) NOT NULL ENABLE,
“DATA” CLOB,
“CREATED_AT” DATE,
“UPDATED_AT” DATE,
PRIMARY KEY (“ID”) ENABLE
)
/

CREATE INDEX “INDEX_SESSIONS_ON_SESSION_ID” ON
“SESSIONS” (“SESSION_ID”)
/

CREATE INDEX “INDEX_SESSIONS_ON_UPDATED_AT” ON
“SESSIONS” (“UPDATED_AT”)
/

But now, when I try to start my application, I get an error I’ve been
unable to solve. This is the error:

/!\ FAILSAFE /!\ Wed Dec 24 22:36:41 -0500 2008
Status: 500 Internal Server Error
“DESC session” failed; does it exist?
(eval):3:in ‘describe’
c:/ruby/lib/ruby/gems/1.8./gems/activerecord-oracle-adapter01.0.0.9250/
lib/active_record/connection_adapters/oracle_adapter.rb:334: in
‘columns’

And here are the first 2 lines of the method:

    def columns(table_name, name = nil) #:nodoc:
      (owner, table_name) = @connection.describe(table_name)

I believe the problem is in the table name change I made (from
singular to plural). I have looked to see if there was a way in Rails
to override the name of the table that stores session information but
couldn’t find any.

I really would appreciate some help on this.

Thanks in advance.

Pepe


#2

I want to thank whoever sent me the answer below to my e-mail address.
I tried to answer the e-mail but the e-mail server returned the e-mail
saying the address didn’t exist.

This did the trick, but it sparkled another question. I tried to dig
through the Rails and Ruby documentations to get to the class where
the ‘magic’ happens and I am too dense to figure out where it is. I
would appreciate if somebody shed some light on how to get there.

Thanks a lot.

Pepe

# You may configure the table name, primary key, and data column.
# For example, at the end of <tt>config/environment.rb</tt>:
#   CGI::Session::ActiveRecordStore::Session.table_name =

‘legacy_session_table’
# CGI::Session::ActiveRecordStore::Session.primary_key =
‘session_id’
# CGI::Session::ActiveRecordStore::Session.data_column_name =
‘legacy_session_data’
# Note that setting the primary key to the +session_id+ frees you
from
# having a separate +id+ column if you don’t want it. However,
you must
# set session.model.id = session.session_id by hand! A
before filter
# on ApplicationController is a good place.

/usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
session/active_record_store.rb


#3

“You may configure the table name, primary key, and data column.
For example, at the end of config/environment.rb:
CGI::Session::ActiveRecordStore::Session.table_name =
‘legacy_session_table’
CGI::Session::ActiveRecordStore::Session.primary_key = ‘session_id’
CGI::Session::ActiveRecordStore::Session.data_column_name =
‘legacy_session_data’
Note that setting the primary key to the +session_id+ frees you from
having a separate +id+ column if you don’t want it. However, you must
session.model.id = session.session_id by hand! A before
filter
on ApplicationController is a good place.”

/usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
session/active_record_store.rb