2024-05-17 09:09:32 -04:00
|
|
|
class Settings::ProfilesController < SettingsController
|
2024-04-18 07:56:51 -04:00
|
|
|
def show
|
2024-02-05 22:19:23 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2024-02-10 16:18:56 -06:00
|
|
|
user_params_with_family = user_params
|
2024-03-25 13:06:27 -04:00
|
|
|
|
2024-04-30 18:38:33 +01:00
|
|
|
if params[:user][:delete_profile_image] == "true"
|
|
|
|
Current.user.profile_image.purge
|
|
|
|
end
|
|
|
|
|
2024-04-25 07:54:56 -04:00
|
|
|
if Current.family && user_params_with_family[:family_attributes]
|
2024-02-10 16:18:56 -06:00
|
|
|
family_attributes = user_params_with_family[:family_attributes].merge({ id: Current.family.id })
|
|
|
|
user_params_with_family[:family_attributes] = family_attributes
|
|
|
|
end
|
|
|
|
|
|
|
|
if Current.user.update(user_params_with_family)
|
2024-04-25 07:54:56 -04:00
|
|
|
redirect_to settings_profile_path, notice: t(".success")
|
2024-02-05 22:19:23 +08:00
|
|
|
else
|
2024-08-13 01:38:58 +01:00
|
|
|
redirect_to settings_profile_path, alert: Current.user.errors.full_messages.to_sentence
|
2024-02-05 22:19:23 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-04-30 16:40:31 +01:00
|
|
|
def destroy
|
|
|
|
if Current.user.deactivate
|
|
|
|
logout
|
|
|
|
redirect_to root_path, notice: t(".success")
|
|
|
|
else
|
|
|
|
redirect_to settings_profile_path, alert: Current.user.errors.full_messages.to_sentence
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-02-05 22:19:23 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def user_params
|
2024-04-30 18:38:33 +01:00
|
|
|
params.require(:user).permit(:first_name, :last_name, :profile_image,
|
2024-04-25 07:54:56 -04:00
|
|
|
family_attributes: [ :name, :id ])
|
2024-02-05 22:19:23 +08:00
|
|
|
end
|
|
|
|
end
|