Routes.rb :
resources :users do
collection do
patch 'update_password'
end
end
get 'change_password' => "users#change_password"
users_controller.rb :
def change_password
@user = current_user
end
def update_password
@user = current_user
unless @user.valid_password?(params[:user][:current_password])
@user.errors.add(:base, "Current Password is incorrect.")
return render "change_password"
end
if @user.update(user_params)
# Sign in the user by passing validation in case their password changed
bypass_sign_in(@user)
redirect_to root_path
#redirect_to destroy_user_session_path
else
render "change_password"
end
end
resources :users do
collection do
patch 'update_password'
end
end
get 'change_password' => "users#change_password"
users_controller.rb :
def change_password
@user = current_user
end
def update_password
@user = current_user
unless @user.valid_password?(params[:user][:current_password])
@user.errors.add(:base, "Current Password is incorrect.")
return render "change_password"
end
if @user.update(user_params)
# Sign in the user by passing validation in case their password changed
bypass_sign_in(@user)
redirect_to root_path
#redirect_to destroy_user_session_path
else
render "change_password"
end
end
No comments:
Post a Comment