When someone is logging into my application, I use:
def create
@user = User.authenticate(params[:email], params[:password])
[...]
end
Ok, then, when someone is logging out:
def destroy
user = User.find_by_id(session[:user_id])
[...]
end
Knowledge
As far as I know, variable scopes work based on a scope, at least on Ruby (on Rails).
Our friend said:
In case of controllers, it present for that HTTP request alone, the object and the instance variables.
Ok. My variable scope created on create method is useless for destroy method, but I was thinking about the subject and the following question appears: There's a way to preserve @user for that controller at all, regardless of the HTTP request?
I mean, @ in this case seems useless to me because its not flexible. I don't know, just sounds strange for me I can't reuse it when I want to.
@) is persistent across the existence of a specific class instance. The the last set value of@usershould still exist whendestroyis called. If it is a different instance of the controller class, it will have its own value for@user. In the statementuser = ...indestroy, the variableuseris strictly local to thedestroymethod.