app/helpers/sessions_helper.rb
#return current user's object, if nil, find session recorded user
return current user's object, if nil, find session recorded user
return current user ' s object if nil find session recorded user
def current_user
      if (user_id = session[:user_id]) 
          @current_user ||= User.find_by(id: user_id) 
      elsif (user_id = cookies.signed[:user_id]) 
        user = User.find_by(id: user_id) 
        if user && user.permission != -99 && user.authenticated?(cookies[:remember_token]) 
          log_in user 
          @current_user = user 
        end 
      end
      return @current_user  
    end
def current_user if ( user_id = session [ :user_id ] ) @current_user ||= User . find_by ( id : user_id ) elsif ( user_id = cookies . signed [ :user_id ] ) user = User . find_by ( id : user_id ) if user && user . permission != - 99 && user . authenticated? ( cookies [ :remember_token ] ) log_in user @current_user = user end end return @current_user end
return current user's object, if nil, find session recorded user
return current user ' s object if nil find session recorded user