18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/controllers/my_accounts_controller.rb', line 18
def update
@profile = current_user.profile
user_attrs = [
:id, :email, :current_password, :password, :password_confirmation
]
user_attrs += [
{:user_has_role_attributes => [:id, :role_id]}
] if current_user.has_role?('Administrator')
user_params = ActionController::Parameters.new(params[:profile][:user_attributes]).permit(*user_attrs)
respond_to do |format|
saved = current_user.update_attributes(user_params)
@profile.assign_attributes(profile_params)
if saved
if @profile.save
sign_in(current_user, bypass: true)
format.html { redirect_to my_account_url, notice: t('controller.successfully_updated', model: t('activerecord.models.user')) }
format.json { head :no_content }
else
prepare_options
format.html { render action: "edit" }
format.json { render json: current_user.errors, status: :unprocessable_entity }
end
else
current_user.errors.full_messages.each do |msg|
@profile.errors[:base] << msg
end
prepare_options
format.html { render action: "edit" }
format.json { render json: current_user.errors, status: :unprocessable_entity }
end
end
end
|