From 406d721f1160cc890dd3f5d6cb3cf5352923dc8e Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 4 Apr 2017 14:17:45 +0800 Subject: [PATCH] Fix `NilClass` error in `UsersController`. --- app/controllers/users_controller.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 13eddab750e..28f53334e13 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -392,12 +392,12 @@ class UsersController < ApplicationController token = params[:token] if EmailToken.valid_token_format?(token) - if request.put? - @user = EmailToken.confirm(token) - else - email_token = EmailToken.confirmable(token) - @user = email_token.try(:user) - end + @user = + if request.put? + EmailToken.confirm(token) + else + EmailToken.confirmable(token)&.user + end if @user secure_session["password-#{token}"] = @user.id @@ -438,11 +438,11 @@ class UsersController < ApplicationController format.json do if request.put? - if @error || @user.errors&.any? + if @error || @user&.errors&.any? render json: { success: false, message: @error, - errors: @user.errors.to_hash, + errors: @user&.errors.to_hash, is_developer: UsernameCheckerService.is_developer?(@user.email) } else