
Originally Posted by
Fenrir2
...
;-)
True. If it's an @var variable you don't need to assign nil to it. BUT, maybe there is an after filter that stores the @user object in the session?
no, it is an instance variable declared and assigned in a before method in application.rb and it is assigned only if it is found a session variable that contains the user id logged in so any next request of a user not logged in (or the same user that logged out) doesn't have that instance variable 'cause the session variable isn't found.....so i don't understand wht to bother to assign it a nil value when the user logs out and the session variable is set to nil.
here is the code with the instance variable @current_user:
Code:
def fetch_logged_in_user
return if session[:user_id].blank?
@current_user = User.find_by_id(session[:user_id])
end
...and when the user logs out the session variable session[:user_id] is set to nil:
Code:
def logout
session[:user_id] = @current_user = nil
end
Bookmarks