# Global variable problem in production environment

**URL:** <https://www.ruby-forum.com/t/global-variable-problem-in-production-environment/180528>\
**Category:** Rails\
**Created:** [December 21, 2009, 12:12pm UTC](https://www.ruby-forum.com/t/global-variable-problem-in-production-environment/180528 "2009-12-21T12:12:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nandan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b19c9b/32.png) [@nandan](https://www.ruby-forum.com/u/nandan)\
**Post date:** [December 21, 2009, 12:12pm UTC](https://www.ruby-forum.com/t/global-variable-problem-in-production-environment/180528/1 "2009-12-21T12:12:48Z")

</div>

plz help me anyone we are writing some value to global varible in  
application\_helper file and accessing the same in views and layouts the  
value of global varible changes dynamically whenever user logs in  
(Example if user1 and user2 logs in at same time sometimes user2 is  
veiwing user1 deatils in that global varible we are running the  
application in production mode with apache 2.x version and passeneger  
2.x version ) .plz suggest us how to use global varible in this scenario

---

<div class="post-metadata">

**Author:** ![nandan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b19c9b/32.png) [@nandan](https://www.ruby-forum.com/u/nandan)\
**Post date:** [December 21, 2009, 12:21pm UTC](https://www.ruby-forum.com/t/global-variable-problem-in-production-environment/180528/2 "2009-12-21T12:21:42Z")

</div>

2009/12/21 Nandan K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> plz help me anyone we are writing some value to global varible in  
> application\_helper file and accessing the same in views and layouts the  
> value of global varible changes dynamically whenever user logs in  
> (Example if user1 and user2 logs in at same time sometimes user2 is  
> veiwing user1 deatils in that global varible we are running the  
> application in production mode with apache 2.x version and passeneger  
> 2.x version ) .plz suggest us how to use global varible in this scenario

The solution is to not use global variables. It may be that session  
variables are appropriate for your requirement if you wish data for a  
user to persist across server requests. If you do not require  
persistence then just use instance variables.

Colin

–

You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

---

<div class="post-metadata">

**Author:** ![nandan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b19c9b/32.png) [@nandan](https://www.ruby-forum.com/u/nandan)\
**Post date:** [December 22, 2009, 8:32pm UTC](https://www.ruby-forum.com/t/global-variable-problem-in-production-environment/180528/3 "2009-12-22T20:32:44Z")

</div>

On Dec 21, 6:12 am, Nandan K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> plz help me anyone we are writing some value to global varible in  
> application\_helper file and accessing the same in views and layouts the  
> value of global varible changes dynamically whenever user logs in  
> (Example if user1 and user2 logs in at same time sometimes user2 is  
> veiwing user1 deatils in that global varible we are running the  
> application in production mode with apache 2.x version and passeneger  
> 2.x version ) .plz suggest us how to use global varible in this scenario.

I would say “GB2PHP” based on this, but it wouldn’t work there  
either… 🙂

Seriously - 99% of the time, if you’re using a global variable, you’re  
doing it wrong. Take a look at session variables in the  
ActionController::Base docs:

> **[ActionController::Base](https://api.rubyonrails.org/classes/ActionController/Base.html)**
>
> Action Controllers are the core of a web request in Rails. They are made up of one or more actions that are executed on request and then either it renders a template or redirects to another action.

I’d also _strongly_ recommend that you get a good (recent) Rails  
reference like Agile Web D. with Rails (3rd ed).

–Matt J.

–

You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).
