# When does Rails create a session object?

**URL:** <https://www.ruby-forum.com/t/when-does-rails-create-a-session-object/87991>\
**Category:** Rails\
**Created:** [March 7, 2007, 11:32am UTC](https://www.ruby-forum.com/t/when-does-rails-create-a-session-object/87991 "2007-03-07T11:32:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lee](https://www.ruby-forum.com/u/lee)\
**Post date:** [March 7, 2007, 11:32am UTC](https://www.ruby-forum.com/t/when-does-rails-create-a-session-object/87991/1 "2007-03-07T11:32:53Z")

</div>

I am trying to simulate multiple users accessing my app from the same  
development machine.

To do so, I am trying to understand when Rails creates a session  
object and what triggers this.

My tests indicate that an empty session object is created as soon as  
the server receives a HTTP request from a browser.

If I open up another browser session on my development machine and  
issue another HTTP request, no new session object is created - Rails  
reuses the existing one.

Why is this? Does Rails look at some specific information in the HTTP  
request headers when determining whether or not to create a new  
session object?

I hope this makes sense.

---

<div class="post-metadata">

**Author:** ![lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lee](https://www.ruby-forum.com/u/lee)\
**Post date:** [March 7, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/when-does-rails-create-a-session-object/87991/2 "2007-03-07T13:24:17Z")

</div>

it has to do with your browser.

when a session is created, a cookie is set in your browser for the  
domain your are visiting. this cookie contains the host, path, name  
and value. for example, if i visit localhost:3000/ (my development  
machine), i get a cookie

host: locahost  
path: /  
name: \_session\_id  
content: 1b87c8ad2bc274d96c7efb8a34ca5d3d

cookies exist at the browser level, so if you open a new browser  
tab/window, and access the same page a second time, this cookie data  
is sent as part of the request since it already exists for the domain.

Cookie: \_session\_id=1b87c8ad2bc274d96c7efb8a34ca5d3d

and since you already have a cookie with the session id, and your app  
has a session stored with that id, you won’t get a new one.

you have some options.

1. test your rails app using integration testing to simulate multiple  
users.

2. use 2 different machines.

3. use 2 different browsers (ex: firefox and opera) from the same  
machine.
