(3) cannot save state through requests. Each time a request enters your Rails application, an instance of your controller is created and the corresponding action method is called on it. After the request has been processed, the controller instance is discarded, and a new new one is created for the next request.
(4) can technically save state on request, but data will be available for all instances of your controller, regardless of which user is executing the request. It also cannot be accessed from other controllers, it is lost if the server reboots, and if several instances of your Rails application are launched immediately (which is quite common in production scripts), the contents of the class variable will not be transferred between them.
Developing why such a thing is a bad idea: fooobar.com/questions/266663 / ...
source share