私は最初から認証システムを持っています。ユーザーが「プロファイルの編集」をクリックすると、編集するフィールドに関係なく、現在のパスワードを入力する必要があります。
def update
if params[:user][:password].present?
authenticated = @user.authenticate(params[:user][:current_password])
if authenticated && @user.update(user_params)
redirect_to root_url
flash[:notice] = "Your profile was successfully updated!"
else
@user.errors.add(:current_password, 'is invalid') unless authenticated
render :edit
end
elsif @user.update(user_params)
redirect_to root_url
flash[:notice] = "Your profile was successfully updated!"
else
render :edit
end
end
ユーザーがパスワードを変更したい場合にのみ、認証を呼び出すか、コンテキスト モデルの検証を使用するにはどうすればよいですか?