ruby on rails - How do I store an instance variable across multiple actions in a controller? -
Say I want to store some variables in my controller. I want to start it in an action, want to increase it in another, and read it in another just do not work this variable with @foo
because @foo < / Code> was created after the creation.
I do not want to store this variable in a model
Is there any way to preserve this variable besides accumulating this session?
It seems that I have run this problem many times, and I want to know the best way to go about solving it.
Not really a controller action to call each statement is after the controller's action is finished Is also not available. A new controller example is created for each request, and then discarded at the end of the request.
If you do not want to store it in a session, or database model, you have many options if you want that variable specific to a specific session.
If it is global in all sessions, then you can put it in a @@ class_variable
@instance_variable
, but once you have multiple rail processes You can get disturbance after starting (each of them will have their own copy), or if you are running in Thrasef mode, then you can end up with dirty compatibility insects.
I think you can see something like a memcatch, but you still need a key to some user_id or other session marker (unless it is not global),
Comments
Post a Comment