Last active
August 29, 2015 13:57
-
-
Save waseem/9657432 to your computer and use it in GitHub Desktop.
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
Class User < ActiveRecord::Base | |
def update_password(params) | |
if authenticate(params['current_password']) | |
self.password = params['password'] | |
self.password_confirmation = params['password_confirmation'] | |
class << self | |
validates :password, length: { minimum: 6 } | |
end | |
!!save | |
else | |
self.errors[:current_password] << 'is wrong' | |
false | |
end | |
end | |
end | |
## In controller user.update_password(params) |
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
class UserService | |
def self.update_password(user, params) | |
if user.authenticate(params['current_password']) | |
user.password = params['password'] | |
user.password_confirmation = params['password_confirmation'] | |
class << user | |
validates :password, length: { minimum: 6 } | |
end | |
!!user.save | |
else | |
user.errors[:current_password] << 'is wrong' | |
false | |
end | |
end | |
end | |
## In controller ::UserService.update_password(user, params) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment