I'm going through Michael Hartl's rails tutorial and have come to a point where he defines a virtual attribute, remember_token
and later assigns a value to it in a remember
instance method:
class User < ApplicationRecord
attr_accessor :remember_token
...
def remember
self.remember_token = User.new_token
update_attribute(:remember_digest, User.digest(remember_token))
end
end
He then accesses the value of the virtual attribute in a helper method after remember
is called:
def remember(user)
user.remember
cookies.permanent.signed[:user_id] = user.id
cookies.permanent[:remember_token] = user.remember_token
end
My interpretation was that after the remember
method is executed (and where remember_token
is assigned it's removed from memory. Obviously this isn't the case here because it's still available to use when assigning a new value to cookies.permanent[:remember_token]
.
I guess my source of confusion stems from data persistence. Assuming that the remember_token
is made into an instance variable with the help of attr_accessor
, when does it officially become unavailable?