simplify the profile settings form

This commit is contained in:
Alex Turchyn
2023-06-07 12:04:11 +03:00
parent 219ad2b4a7
commit c34ea8451f
14 changed files with 43 additions and 163 deletions
+7 -19
View File
@@ -3,40 +3,28 @@
class ProfileController < ApplicationController
def update_contact
if current_user.update(contact_params)
redirect_to contact_settings_profile_index_path, notice: 'Contact information successfully updated'
redirect_to settings_profile_index_path, notice: 'Contact information successfully updated'
else
render :contact, status: :unprocessable_entity
render :index, status: :unprocessable_entity
end
end
def update_password
if current_user.update_with_password(password_params)
if current_user.update(password_params)
bypass_sign_in(current_user)
redirect_to password_settings_profile_index_path, notice: 'Password successfully changed'
redirect_to settings_profile_index_path, notice: 'Password successfully changed'
else
render :password, status: :unprocessable_entity
end
end
def update_email
if current_user.update_with_password(email_params)
redirect_to email_settings_profile_index_path, notice: 'Email successfully updated. Please check your new email for confirmation instructions.'
else
render :email, status: :unprocessable_entity
render :index, status: :unprocessable_entity
end
end
private
def contact_params
params.require(:user).permit(:first_name, :last_name, account_attributes: %i[name])
params.require(:user).permit(:first_name, :last_name, :email, account_attributes: %i[name])
end
def password_params
params.require(:user).permit(:current_password, :password, :password_confirmation)
end
def email_params
params.require(:user).permit(:current_password, :email)
params.require(:user).permit(:password, :password_confirmation)
end
end