CGI::Session / mod_ruby problem

Hi everybody,

I am making an AJAX call to login.rhtml, in login.rhtml a new session is
created, and then I use javascript to reload the page to
/interface/index.rhtml where i attempt to continue the session created
in login.rhtml but everytime I do this I get an ArgumentError(from what
ive read means no session exists.) I am using mod_ruby/eruby to do
this.. The code I am using is posted below :

-- login.rhtml --
session = CGI::Session.new(cgiObject,'database_manager' =>
CGI::Session::PStore,
                    'session_key' => '_rb_sess_id',
                    'session_expires' => Time.now + 30 * 60,
              'prefix' => 'sessions_pstore',
              'new_session' => true)

            session['username'] = cgiObject['username']
            session.update
            session.close

-- interface/index.rhtml --
session = CGI::Session.new(cgiObject,'database_manager' =>
CGI::Session::PStore,
               'session_key' => '_rb_sess_id',
               'prefix' => 'sessions_pstore'
               'new_session' => false )
puts session['username']

···

-----------------------------------
I get a server error each time, the error is : [Thu Sep 11 10:38:19
2008] [error] mod_ruby: /usr/lib/ruby/1.8/cgi/session.rb:271:in
`initialize': session_key `_rb_sess_id' should be supplied
(ArgumentError)
--
Posted via http://www.ruby-forum.com/.

The code looks okay to me what you can do:

1. Add 'session_path' => '/' to the options of CGI::Session.new if
your scripts are in different directories.
2. Check in your browser if the cookie is really set (firefox ->
Preferences -> privacy -> Show cookies)
3. Check if the login.rhtml can see the cookie before you set it again. (e.g.
new_session => 'false' ... puts session.inspect). As a test.

martin

···

On Thursday 11 September 2008 09:55:41 Robert Gleeson wrote:

Hi everybody,

I am making an AJAX call to login.rhtml, in login.rhtml a new session is
created, and then I use javascript to reload the page to
/interface/index.rhtml where i attempt to continue the session created
in login.rhtml but everytime I do this I get an ArgumentError(from what
ive read means no session exists.) I am using mod_ruby/eruby to do
this.. The code I am using is posted below :

-- login.rhtml --
session = CGI::Session.new(cgiObject,'database_manager' =>
CGI::Session::PStore,
                    'session_key' => '_rb_sess_id',
                    'session_expires' => Time.now + 30 * 60,
              'prefix' => 'sessions_pstore',
              'new_session' => true)

            session['username'] = cgiObject['username']
            session.update
            session.close

-- interface/index.rhtml --
session = CGI::Session.new(cgiObject,'database_manager' =>
CGI::Session::PStore,
               'session_key' => '_rb_sess_id',
               'prefix' => 'sessions_pstore'
               'new_session' => false )
puts session['username']

-----------------------------------
I get a server error each time, the error is : [Thu Sep 11 10:38:19
2008] [error] mod_ruby: /usr/lib/ruby/1.8/cgi/session.rb:271:in
`initialize': session_key `_rb_sess_id' should be supplied
(ArgumentError)

Thanks Martin, I set "session_path" => '/' in the interface/index.rhtml
file which resulted in the problem being solved. Thanks a million for
your help!

···

--
Posted via http://www.ruby-forum.com/.