# :active\_record\_store + :table\_name\_with\_underscore session issues

**URL:** <https://www.ruby-forum.com/t/active-record-store-table-name-with-underscore-session-issues/158868>\
**Category:** Rails\
**Created:** [January 28, 2009, 10:25pm UTC](https://www.ruby-forum.com/t/active-record-store-table-name-with-underscore-session-issues/158868 "2009-01-28T22:25:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![destiney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@destiney](https://www.ruby-forum.com/u/destiney)\
**Post date:** [January 28, 2009, 10:25pm UTC](https://www.ruby-forum.com/t/active-record-store-table-name-with-underscore-session-issues/158868/1 "2009-01-28T22:25:44Z")

</div>

Today I created a new Rails 2.2.2 project.

I’m using Oracle and activerecord-oracle-adapter (1.0.0.9250).

I’m using ActiveRecord::Base.primary\_key\_prefix\_type =  
:table\_name\_with\_underscore, which is a spec for the project that I  
cannot change.

I ran `rake db:sessions:create` and it created a new migration that  
looks like this:

class CreateSessions \< ActiveRecord::Migration

def self.up  
create\_table :sessions do |t|  
t.string :session\_id, :null =\> false  
t.text :data  
t.timestamps  
end  
add\_index :sessions, :session\_id  
add\_index :sessions, :updated\_at  
end

def self.down  
drop\_table :sessions  
end

end

This does not work. I get the error:  
ActionController::InvalidAuthenticityToken on any forms that are  
posted.

When I look in the sessions table the hashed data in the `data` field  
looks normal, but there are integers being stored in the session\_id  
field, not the 32 character hashes I would expect. And every page  
reload creates a new session, the integer stored in the session\_id  
field is incremented by one. I’m thinking session data is being  
written, but then cannot be retrieved.

I’ve tried a number of things I found searching, such as:

CGI::Session::ActiveRecordStore::Session.set\_primary\_key ‘session\_id’

none of which help. Any idea what I need to do?

I have other, older Rails apps using active\_record\_store sessions that  
work just fine, but this is my first one on Rails 2.2.2 and so far  
it’s a no-go.

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![destiney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@destiney](https://www.ruby-forum.com/u/destiney)\
**Post date:** [January 29, 2009, 1:26am UTC](https://www.ruby-forum.com/t/active-record-store-table-name-with-underscore-session-issues/158868/2 "2009-01-29T01:26:49Z")

</div>

You may want to browse:

[http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html](http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html)

and

> **[ActionController::RequestForgeryProtection](https://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html)**
>
> Controller actions are protected from Cross-Site Request Forgery (CSRF) attacks by including a token in the rendered HTML for your application.

Good luck!  
Tim

---

<div class="post-metadata">

**Author:** ![destiney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@destiney](https://www.ruby-forum.com/u/destiney)\
**Post date:** [January 29, 2009, 1:36am UTC](https://www.ruby-forum.com/t/active-record-store-table-name-with-underscore-session-issues/158868/3 "2009-01-29T01:36:46Z")

</div>

On 29 Jan 2009, at 00:26, Tim wrote:

> > When I look in the sessions table the hashed data in the `data` field  
> > looks normal, but there are integers being stored in the session\_id  
> > field, not the 32 character hashes I would expect. And every page  
> > reload creates a new session, the integer stored in the session\_id  
> > field is incremented by one. I’m thinking session data is being  
> > written, but then cannot be retrieved.

Hmm. The problem you have is that by setting primary key  
to :table\_name\_with\_underscore rails wants to use session\_id as the  
primary key to the sessions table. it also wants to use session\_id for  
the session identifier and for whatever reason, the primary key ‘wins’.  
You could fiddle the SessionClass for it to store the session  
identifier in a different column (or  
CGI::Session::ActiveRecordStore::Session.set\_primary\_key ‘id’ would  
probably do the trick if you can get away with it.

Fred

---

<div class="post-metadata">

**Author:** ![destiney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@destiney](https://www.ruby-forum.com/u/destiney)\
**Post date:** [January 29, 2009, 8:07pm UTC](https://www.ruby-forum.com/t/active-record-store-table-name-with-underscore-session-issues/158868/4 "2009-01-29T20:07:57Z")

</div>

On Wed, Jan 28, 2009 at 6:35 PM, Frederick C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hmm. The problem you have is that by setting primary key  
> to :table\_name\_with\_underscore rails wants to use session\_id as the  
> primary key to the sessions table. it also wants to use session\_id for  
> the session identifier and for whatever reason, the primary key ‘wins’.  
> You could fiddle the SessionClass for it to store the session  
> identifier in a different column (or  
> CGI::Session::ActiveRecordStore::Session.set\_primary\_key ‘id’ would  
> probably do the trick if you can get away with it.

I appreciate the reply but I’m not gonna bother trying to figure it  
out, I switched to memory sessions this morning and it works with no  
problems.

I’m not really understanding how I can have another app on Rails 2.0.2  
that has this exact same setup and it works fine. Something changed  
from 2.0.2 → 2.2.2 which obviously didn’t break any Rails core  
tests… I mean, if anyone is even testing on anything besides MySQL.  
To use Rails in medical research means Oracle most of the time.

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)
