views:

23

answers:

2

I have few variables which are used system-wide in my rails app. It runs well if I just have one user using the app. If there are more then one user, many unexpected problem pop out. I don't get any error log, and I have many unexpected behaviors. I believe most of those strange response are due to unexpected change of global variable.

I would like to know, is the value of global variable in Rails shared between different users?

thanks~

+1  A: 

Global variables are a sign of [very/really] bad design. Have you considered SimpleConfig gem for this?

Eimantas
Thanks buddy. Can SimpleConfig manage different Setting Variables value based on different user action? i.e. UserA and UserB using the same app that the Setting Variables will change based on their input.
siulamvictor
If you need a per-user variables, I'd suggest storing them in a table. Otherwise if you need separate users configuring app globally - use simple config.
Eimantas
get it.... thanks so much. :)
siulamvictor
+1  A: 

This seems to be dependant upon your method of deployment.

It seems that mongrel and any fastcgi based deployment will each see different instances of the global variable whereas passenger will share it. This is based upon #821820 and many articles on rails and global variables including this one.

To re-iterate what Eimantas said above, globals are generally a bad idea and you should consider another alternative, perhaps storing them in the database or session.

Steve Weet
thanks buddy. i am now studying session store with active records. hope this can fix my problem. ;)
siulamvictor