Guest User

Untitled

a guest
May 7th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. # PUT /users/1
  2. # PUT /users/1.xml
  3. def update
  4. @user = User.find(session[:user_id])
  5.  
  6. unless @user.validate_password(params[:user][:current_password])
  7. @user.attributes = params[:user]
  8. @user.valid?
  9.  
  10. @user.errors.add("current_password")
  11. render :action => "edit"
  12. return
  13. end
  14.  
  15. if @user.valid? && !params[:user][:new_password].empty?
  16. @user.password = params[:user][:new_password]
  17. end
  18.  
  19. respond_to do |format|
  20. if @user.update_attributes(params[:user])
  21. flash[:notice] = 'Account details successfully updated.'
  22. format.html { redirect_to(edit_user_path(@user)) }
  23. else
  24. format.html { render :action => "edit" }
  25. end
  26. end
  27. end
Add Comment
Please, Sign In to add comment