Forum: Ruby on Rails Question about object: session and controllers

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
14b7344777a56ac9a1fad849f5d6da2a?d=identicon&s=25 sayoyo (Guest)
on 2005-11-25 15:46
(Received via mailing list)
Hi,

Does someone know where exactly the object session is
stored? on the server side or on the client side? And
how rails accesses to that data ( with the
session_id?, where is it exactly?)

and does the session obj is sent to client each time a
request or an answer?

The controllers objects do they recreted each time by
the rails each time it receives a request, or there is
"objects pool" that the controller is stored after it
is created, then wait for a request?


Thanks you very much

Saiho





__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
2ee1028723473faa763884e902ce3366?d=identicon&s=25 thiessen (Guest)
on 2005-11-25 17:23
(Received via mailing list)
Saiho Yuen <sayoyo@...> writes:
> Does someone know where exactly the object session is
> stored? on the server side or on the client side? And
> how rails accesses to that data ( with the
> session_id?, where is it exactly?)
>
> and does the session obj is sent to client each time a
> request or an answer?

If a user has no session "object" associated with them (for example,
they are
just connecting to your application for the first time), Rails will
automatically, with no code on your part, create a new session data
structure
and save a cookie with it's identification information into the client
browser.
 From then on, every time the client sends an HTTP request to your
application,
it will automatically transmit that session identification cookie to
your
application. Behind the scenes, Rails receives that cookie, maps it to
one of
the currently active session data structures, and makes that structure
available
to your application as the "session[]" hash-like object.

Session data is stored on the server, and is never sent to the
client--all the
client gets is the cookie containing identifying information. The
session id
cookie is set to expire when you close your browser window, so at that
time it
gets deleted. When the user opens a new browser window and connects
again, a new
session is created, it's identification cookie is created and sent to
the
browser, and the cycle starts all over again.

On the server the session data is stored in a file somewhere; one of
Rails
configuration options lets you change it so it will be stored in a
special table
in your database, in memory, or several other options.

All of this is described in detail in Agile Web Development with Rails,
pages
312-321.



> The controllers objects do they recreted each time by
> the rails each time it receives a request, or there is
> "objects pool" that the controller is stored after it
> is created, then wait for a request?

The classes corresponding to your controllers are created when your
Rails
application starts. Every time a new request comes in from the client,
Rails
uses its routing logic to identify which controller should be called,
and then
*at the time of the request*, it creates an instance of the appropriate
controller class and calls the requested action (method) of that
instance. These
instances are supposed to be discarded when the request processing is
finished;
so there is no "object pool".

What might be causing some confusion is that if you're using certain web
server
environments--for example, FastCGI--a pool of copies of the Rails
processes
(dispatch.fcgi) will kept running by the web server, each process
waiting to
receive new requests, and carrying a limited amount of state over from
one
request to the next. Your controller instances will be created and
destroyed
within those processes.

--Forrest
14b7344777a56ac9a1fad849f5d6da2a?d=identicon&s=25 sayoyo (Guest)
on 2005-11-25 17:35
(Received via mailing list)
Thanks you very much for the information!!!!!

Saiho


--- Forrest Thiessen <thiessen@cyberscapearena.com>
wrote:

> > request or an answer?
> request to your application,
> sent to the client--all the
> On the server the session data is stored in a file
>
> created when your Rails
> so there is no "object pool".
> be created and destroyed
> within those processes.
>
> --Forrest
>
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


If God really exists, I would like to
know what the dinosaurs have done to
deserve their extinction.

Water is unknown to fishes,
until they discover air.

http://www.geocities.com/sayoyo/




__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
This topic is locked and can not be replied to.