# Class variables and servers

**URL:** <https://www.ruby-forum.com/t/class-variables-and-servers/175466>\
**Category:** Rails\
**Created:** [September 14, 2009, 11:35am UTC](https://www.ruby-forum.com/t/class-variables-and-servers/175466 "2009-09-14T11:35:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marmolin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71e660/32.png) [@marmolin](https://www.ruby-forum.com/u/marmolin)\
**Post date:** [September 14, 2009, 11:35am UTC](https://www.ruby-forum.com/t/class-variables-and-servers/175466/1 "2009-09-14T11:35:24Z")

</div>

In my local development environment I define a class variabel  
@@has:flock? in a modele that is included in controllers so I can  
reset this variable in each controller that has to change it  
The code in the module is  
module CrudActions  
@@page\_records=15  
@@has\_flock = true

def index  
if @@has\_flock : paginate\_conditions=[‘flock\_id=?  
‘,current\_user.flock.id]  
else paginate\_conditions=’’ end

…and in the controller  
class DiswebUsersController \< ApplicationController  
include CrudActions  
@@page\_records=15  
…

That works fine locally but when I deploy the application and use an  
apache server it does not work anymore (@@has\_flock? is false) in the  
method index  
Then the variable is not set in the module  
Any idees of what is happening ?  
I can fix it by defining a method, but I wauld like to know if that is  
necessery  
Any help is appreciate?

---

<div class="post-metadata">

**Author:** ![marmolin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71e660/32.png) [@marmolin](https://www.ruby-forum.com/u/marmolin)\
**Post date:** [September 15, 2009, 9:57pm UTC](https://www.ruby-forum.com/t/class-variables-and-servers/175466/2 "2009-09-15T21:57:45Z")

</div>

Hi Hans,

processes don’t know each other and i.g. you can’t control which  
instance of  
your Application responds to the next request, this means:

Apache (T=0)  
|

- \< Application (Process 0)  
| @@flock = nil  
|  
|
- 

> Fork’d Application (Process 1)  
> | @@flock = nil  
> |

- 

> Fork’d Application (Process 2)  
> @@flock = nil

* * *

Apache (T=1)  
|

- \< Application (Process 0)  
| @@flock = nil  
|  
|
- 

> Fork’d Application (Process 1)  
> | @@flock = nil  
> |

- 

> Fork’d Application (Process 2) \< - REQUEST 1 _200_  
> @@flock = nil

* * *

Apache (T=2)  
|

- \< Application (Process 0)  
| @@flock = nil  
|  
|
- 

> Fork’d Application (Process 1) \< - REQUEST 2 _500_  
> | @@flock = nil  
> |

- 

> Fork’d Application (Process 2)  
> @@flock = true

If you use Mongrel or Thin whereas only a single Process for your  
application  
exists the class variable is always the same.

Thin (T=0, Process 0)  
|

- \<\> Application  
@@flock = nil

* * *

Thin (T=1, Process 0)  
|

- \<\> Application \< - REQUEST 1 _200_  
@@flock = nil

* * *

Thin (T=2, Process 0)  
|

- \<\> Application \< - REQUEST 2 _200_  
@@flock = true

* * *

Regards  
Florian

Am 14.09.2009 um 11:33 schrieb Hans:
