Re: [Rails] Re: Re: Re: Ruby class variables and access from view templa

Kevin Olbrich devlists-rubyonrails at devlists.com
Sat Feb 18 07:11:53 GMT 2006


I would be interested to see if there are differences in class variable  
handling between development and production mode.  In development mode a  
lot of the code gets reloaded every request, but in production mode this  
doesn't happen so much.

As a general rule it is probably best to avoid using class variables to  
store stuff.  If you scale your app to multiple web servers, the next  
request might not go back to the same box and would not have access to  
anything you put in the class variable.

You should probably use one of the following to get the same effect..

1. store it in the database
2. use the session hash
3. use a before_filter
4. write it to a temp file

An enterprising person could probably write a plugin that would emulate  
the typical class variable behavior by using one the previously  
mentioned methods to store the contents.

_Kevin

-- 
Posted with http://DevLists.com.  Sign up and save your time!


More information about the Rails mailing list