# CGI::Session / mod\_ruby problem

**URL:** <https://www.ruby-forum.com/t/cgi-session-mod-ruby-problem/148292>\
**Category:** Ruby\
**Created:** [September 11, 2008, 12:02pm UTC](https://www.ruby-forum.com/t/cgi-session-mod-ruby-problem/148292 "2008-09-11T12:02:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [September 11, 2008, 12:02pm UTC](https://www.ruby-forum.com/t/cgi-session-mod-ruby-problem/148292/1 "2008-09-11T12:02:19Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [September 11, 2008, 5:31pm UTC](https://www.ruby-forum.com/t/cgi-session-mod-ruby-problem/148292/2 "2008-09-11T17:31:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [September 13, 2008, 6:25pm UTC](https://www.ruby-forum.com/t/cgi-session-mod-ruby-problem/148292/3 "2008-09-13T18:25:49Z")

</div>

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!
