Created
September 21, 2012 17:13
-
-
Save timcheadle/3762711 to your computer and use it in GitHub Desktop.
Allow Users to edit their profile/settings in Devise without requiring the current password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Custom registration handlers for users (override devise's defaults) | |
# | |
class Users::RegistrationsController < Devise::RegistrationsController | |
before_filter :authenticate_user! | |
# Override the devise update method for registrations | |
def update | |
@user = User.find(current_user.id) | |
# See https://github.com/plataformatec/devise/wiki/How-To%3A-Allow-users-to-edit-their-account-without-providing-a-password | |
password_changed = !params[:user][:password].blank? | |
successfully_updated = if password_changed | |
@user.update_attributes(params[:user]) | |
else | |
@user.update_without_password(params[:user]) | |
end | |
if successfully_updated | |
sign_in @user, :bypass => true | |
redirect_to @user, notice: 'User was successfully updated.' | |
else | |
render 'edit' | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
devise_for :users, :controllers => { :registrations => "users/registrations" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment