Created
November 10, 2014 13:37
-
-
Save messiahxu/2c7253cb09379f479b66 to your computer and use it in GitHub Desktop.
rails 4 user update_without_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
class User < ActiveRecord::Base | |
..... | |
# password section | |
has_secure_password | |
validates :password, length: { in: 6..30 }, if:->{password.present?} | |
....... | |
def update_without_password(params = {}) | |
params.delete(:password) | |
params.delete(:password_confirmation) | |
result = self.update_attributes(params) | |
end | |
....... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment