docbrown/app/controllers/profiles_controller.rb
Ramesh Naidu Allu 0911cd4a5c
Save valid attributes with ignoring the invalid ones (#12633)
* add save_valid_attributes method in profile

* undo save_valid_attributes method

* Render the settings page with user entered params incase of failed update
2021-03-24 10:42:58 +01:00

26 lines
758 B
Ruby

class ProfilesController < ApplicationController
before_action :authenticate_user!
ALLOWED_USER_PARAMS = %i[name email username profile_image].freeze
def update
update_result = Profiles::Update.call(current_user, update_params)
if update_result.success?
flash[:settings_notice] = "Your profile has been updated"
redirect_to user_settings_path
else
@user = current_user
@tab = "profile"
flash[:error] = "Error: #{update_result.errors_as_sentence}"
render template: "users/edit", locals: {
user: update_params[:user],
profile: update_params[:profile]
}
end
end
private
def update_params
params.permit(profile: Profile.attributes, user: ALLOWED_USER_PARAMS)
end
end