2024-02-05 22:19:23 +08:00
|
|
|
class SettingsController < ApplicationController
|
|
|
|
def edit
|
|
|
|
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-02-10 16:18:56 -06:00
|
|
|
if Current.family
|
|
|
|
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-02-05 22:19:23 +08:00
|
|
|
redirect_to root_path, notice: "Profile updated successfully."
|
|
|
|
else
|
|
|
|
render :edit, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def user_params
|
|
|
|
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation,
|
2024-02-10 16:18:56 -06:00
|
|
|
family_attributes: [ :name, :id, :currency ])
|
2024-02-05 22:19:23 +08:00
|
|
|
end
|
|
|
|
end
|