如果找不到用户,我有一个返回用户或 nil 的函数。它看起来像这样:
# Given an access token in the HTTP headers, it returns the User who owns the token
#
# @return [User] the user who owns the access token
def set_api_user
token = /(.*)=\"(.*)\"/.match(request.headers["Authorization"])[2]
@api_user = ApiKey.find_by(access_token: token).user
end
我的问题是,如果找不到它,我如何记录它返回用户或 nil?