Skip to content

Instantly share code, notes, and snippets.

@raecoo
Created June 28, 2012 03:04
Show Gist options
  • Save raecoo/3008609 to your computer and use it in GitHub Desktop.
Save raecoo/3008609 to your computer and use it in GitHub Desktop.
Customized Devise
# in routes.rb
devise_for :users, :controllers => { :registrations => "registrations" }
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
# anywhere you want to go
end
def after_update_path_for(resource)
# anywhere you want to go
end
end
# override the update_with_password method in Resource
def update_with_password(params={})
current_password = params.delete(:current_password)
if params[:password].blank?
params.delete(:password)
params.delete(:password_confirmation) if params[:password_confirmation].blank?
end
# result = if valid_password?(current_password)
result = if params[:password].blank? && params[:password_confirmation].blank? || valid_password?(current_password)
update_attributes(params)
else
self.attributes = params
self.valid?
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
false
end
clean_up_passwords
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment