Skip to content

Commit 5a370a3

Browse files
committed
Added profile update action
1 parent 622a1dc commit 5a370a3

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

saasapp/app/controllers/profiles_controller.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def create
1414
@profile = @user.build_profile( profile_params )
1515
if @profile.save
1616
flash[:success] = "Profile updated!"
17-
redirect_to user_path( params[:user_id] )
17+
redirect_to user_path(id: params[:user_id])
1818
else
1919
render action: :new
2020
end
@@ -26,6 +26,22 @@ def edit
2626
@profile = @user.profile
2727
end
2828

29+
# PATCH to /users/:user_id/profile
30+
def update
31+
# Retrieve the user from the database
32+
@user = User.find( params[:user_id] )
33+
# Retrieve that user's profile
34+
@profile = @user.profile
35+
# Mass assign edited profile attributes and save (update)
36+
if @profile.update_attributes( profile_params )
37+
flash[:success] = "Profile updated!"
38+
# Redirect user to their profile page
39+
redirect_to user_path(id: params[:user_id])
40+
else
41+
render action: :edit
42+
end
43+
end
44+
2945
private
3046
def profile_params
3147
params.require(:profile).permit(:first_name, :last_name, :avatar, :job_title, :phone_number, :contact_email, :description)

0 commit comments

Comments
 (0)