내 응용 프로그램에 사용자 확인 프로세스가 있습니다. 네 가지까지 사용자가 로그인이 발생할 경우 :Ruby on Rails 사용자 확인이 매개 변수를 업데이트하지 않음
account_status_id은 new_account_confirmation_token가 발생- 새 사용자에게 new_account_confirmation_token이 포함 된 링크로 전송됩니다.
처음에는이 방법으로 확인 링크를 처리하려고 시도했습니다. 그것은 문제없이 사용자를 찾고 코드는 update_attributes를 통해 전달됩니다! 메서드를 사용했지만 account_status를 업데이트하지 않았습니다. 내가 말할 수있는 사실은 current_user 개체가 존재한다는 사실에 기인합니다. 따라서 업데이트하려는 사용자는 이미 "메모리에 있음"입니다. 그 맞습니까?
def new_account_confirmation
@title = "Account Confirmation"
logger.info("User is not logged in")
@user = User.find_by_new_account_confirmation_token(params[:confirm_id])
if @user
@user.update_attributes!(:account_status_id => 2)
else
redirect_to root_path
end
end
내 해결 방법은 다음과 같습니다. 아래 코드는 작동하지만 위의 코드가 작동하지 않는 이유를 알고 싶습니다. account_status가 업데이트되지 않는 이유는 무엇입니까?
def new_account_confirmation
@title = "Account Confirmation"
if current_user
logger.info("User is logged in")
current_user.update_attributes!(:account_status_id => 2)
else
logger.info("User is not logged in")
@user = User.find_by_new_account_confirmation_token(params[:confirm_id])
if @user
@user.update_attributes!(:account_status_id => 2)
else
redirect_to root_path
end
end
end
첫 번째 코드 집합이 데이터베이스의 행을 업데이트하는지 확인할 수 있습니까? 그것은 올바른 것 같습니다. 하지만 예, 나는 current_user가 메모리에 있기 때문에 업데이트하지 않는다고 생각합니다. 호기심 때문에 세션에서 전체 사용자 객체를 직렬화하고 있습니까? 일반적으로 ID를 저장하고 요청에 따라 쿼리하면 항상 최신 정보를 얻을 수 있습니다. – agmcleod
첫 번째 방법은 데이터베이스의 행을 업데이트하지 않습니다. 그리고 나는 current_user 객체가 아닌 user_id만을 세션에 저장하고 있습니다. – hoitomt