Singleton Pattern in RoR

Hi all

how can I implement the singleton patter in RoR?

thanks

On Oct 16, 2006, at 22:10, Jose P. wrote:

Hi all

how can I implement the singleton patter in RoR?

include Singleton


Jakob S. - http://mentalized.net

Hi Jose,

The Singleton module that Jakob mentioned comes with Ruby, not rails.
You can read about it in the ruby docs.

Cheers
Starr

Justin F. wrote:

Starr wrote:

Hi Jose,

The Singleton module that Jakob mentioned comes with Ruby, not rails.
You can read about it in the ruby docs.

Be aware that a Rails application that needs to handle concurrent
requests will do that by having multiple server processes (Mongrel,
FastCGI, SCGI, …) behind a web server or load balancer. Each server
process will have its own singleton instance. That is OK if you just
want a singleton holding fixed data, but won’t allow you to share
dynamic application state between requests and sessions.

regards

Justin F.

Hi Justin,
2 years later …
I’m looking for a non dirty way to implement a view with a progress bar
who indicates the status of a certain task who takes some time to
achieive.
The task will be lunched in a thread.
I first tried using a singleton class with the thread as an instance
variable, but I realized that a different server thread serves each
request, and so has one instance of the singleton.
So it’s not a good option.
Does anybody know how I should implement something like that ? I done it
before passing by a file on disk to get the status of the thread. I
posted a more detailed question here :

http://railsforum.com/viewtopic.php?pid=101201#p101201

Thanks

Starr wrote:

Hi Jose,

The Singleton module that Jakob mentioned comes with Ruby, not rails.
You can read about it in the ruby docs.

Be aware that a Rails application that needs to handle concurrent
requests will do that by having multiple server processes (Mongrel,
FastCGI, SCGI, …) behind a web server or load balancer. Each server
process will have its own singleton instance. That is OK if you just
want a singleton holding fixed data, but won’t allow you to share
dynamic application state between requests and sessions.

regards

Justin F.