Instance variable in controller with Ruby on Rails

When someone logs into my application, I use:

def create
    @user = User.authenticate(params[:email], params[:password])

    [...]
end

So, when someone logs out:

def destroy
    user = User.find_by_id(session[:user_id])

    [...]
end

Knowledge

As far as I know, it variable scopes works on the basis of a field , at least on Ruby (on Rails).

Our friend said:

In the case of controllers, it is present only for this HTTP request, object, and instance variables.

Ok My variable area created by the method createis useless for the method destroy, but I was thinking about the subject, and the following question appears: is there a way to save @userfor this controller at all, regardless of the HTTP request?

, @ , . , , , .

+3
1

- http " ". , , . . , , . Rails, , , , !

( , URL). @ , ( Ruby , Rails , , , ).

+7

All Articles