Session in ActiveRecordStore


#1

The Agile book seems to say I should specify this as follows, probably
in the
environments.rb:

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:database_manager]

CGI::Session::ActiveRecordStore

BUT the environments.rb file would have me Un-Comment this:

config.action_controller.session_store = :active_record_store

Anyway, I’ve tried both, and in both cases it generates new sessions all
too quickly, so
that no page sees the same session as the page before it. The sessions
appear in the
database. But as far as rails is concerned it only reads blank virginal
sessions over and
over. So no flash appears either. All it has to do is redirect to a
different page and
the session_id in the log is different, so the session is new and
“blank”.

Any ideas why rails is erasing and/or not finding it’s own sessions?
How do I gain
control over session creation and destruction? And if Rails is having
trouble reading the
sessions table from the database, shouldn’t it complain? Can I get
Rails to log the SQL
it uses to create and possibly retrieve the rows from the sessions
table?

Warren Fred


#2

MessageAre you testing the page on a normal browser (e.g. firefox, ie)?
Most
probably, your client is not retaining the session cookies and that’s
why
rails is generating a new one on every request.

“Warren S.” removed_email_address@domain.invalid wrote in
message news:016f01c679e2$54074450$23cd19ac@Whatever…
The Agile book seems to say I should specify this as follows, probably
in
the environments.rb:

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:database_manager]

CGI::Session::ActiveRecordStore

BUT the environments.rb file would have me Un-Comment this:

config.action_controller.session_store = :active_record_store

Anyway, I’ve tried both, and in both cases it generates new sessions all
too
quickly, so that no page sees the same session as the page before it.
The
sessions appear in the database. But as far as rails is concerned it
only
reads blank virginal sessions over and over. So no flash appears
either.
All it has to do is redirect to a different page and the session_id in
the
log is different, so the session is new and “blank”.

Any ideas why rails is erasing and/or not finding it’s own sessions?
How do
I gain control over session creation and destruction? And if Rails is
having trouble reading the sessions table from the database, shouldn’t
it
complain? Can I get Rails to log the SQL it uses to create and possibly
retrieve the rows from the sessions table?

Warren Fred


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


#3

On May 17, 2006, at 11:47 AM, Warren S. wrote:

Anyway, I’ve tried both, and in both cases it generates new
sessions all too quickly, so that no page sees the same session as
the page before it. The sessions appear in the database. But as
far as rails is concerned it only reads blank virginal sessions
over and over. So no flash appears either. All it has to do is
redirect to a different page and the session_id in the log is
different, so the session is new and “blank”.

Sorry if it’s a no-brainer, but you have cookies enabled?

You can check for it in your controllers:

class ApplicationController < ActionController::Base
protected
# Before filter: redirect to no cookies page if _session_id
cookie is missing.
def must_have_session_cookie
if cookies[’_session_id’]
true
else
redirect_to :controller => ‘about’, :action => ‘cookies’
false
end
end
end

class FooController < ApplicationController
before_filter :must_have_session_cookie, :except =>
[:login, :signup]
end

Best,
jeremy


#4

Firefox. The problem only appeared when I changed the session store
from the default
pstore to using active record. I used the rake command to create the
migration and then
ran the ‘rake migrate’. Then I changed the environment to specify
active record for
sessions and restarted webbrick.

Oops: I had changed the :session_key. Was I supposed to change the
session key AFTER I
generated the sessions table? Changing the sessions key is needed when
there is more than
one rails application in a server. Which is normal.

Changing the sessions key back fixed it. So how do I generate another
session from the
same browser?

Warren S.