Skip to content

Instantly share code, notes, and snippets.

@timcheadle
Created September 21, 2012 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timcheadle/3762711 to your computer and use it in GitHub Desktop.
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
#
# 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
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