I have an auth system from scratch, and when a user clicks on 'edit profile' it has to input the current password no matter the field he wants to edit.
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
How can I call authenticate or use some context model validation only for the scenario when the user wants to change his password?