Site para o estudio Velvet Design em São Paulo. http://velvetdesign.com.br

registrations_controller.rb 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. class Users::RegistrationsController < Devise::RegistrationsController
  2. # layout 'auth'
  3. def update
  4. @user = User.find(current_user.id)
  5. successfully_updated = if needs_password?(@user, params)
  6. @user.update_with_password(devise_parameter_sanitizer.sanitize(:account_update))
  7. else
  8. # remove the virtual current_password attribute
  9. # update_without_password doesn't know how to ignore it
  10. params[:user].delete(:current_password)
  11. params[:user].delete(:password)
  12. params[:user].delete(:password_confirmation)
  13. @user.update_without_password(devise_parameter_sanitizer.sanitize(:account_update))
  14. end
  15. if successfully_updated
  16. set_flash_message :notice, :updated
  17. # Sign in the user bypassing validation in case his password changed
  18. sign_in @user, :bypass => true
  19. redirect_to after_update_path_for(@user)
  20. else
  21. render "edit"
  22. end
  23. end
  24. def after_sign_up_path_for(resource)
  25. root_path
  26. end
  27. private
  28. # check if we need password to update user data
  29. # ie if password or email was changed
  30. # extend this as needed
  31. def needs_password?(user, params)
  32. user.email != params[:user][:email] ||
  33. params[:user][:password].present?
  34. end
  35. end