Created
April 6, 2011 19:47
-
-
Save coffeeaddict/906371 to your computer and use it in GitHub Desktop.
callbacks dont invalidate records
This file contains hidden or 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 Member < ActiveRecord::Base | |
SALT = "some lengthy secret" | |
before_create :hash_password | |
# in rails 2 this would break the callback chain and set the error message | |
# in rails 3 it doesnt | |
# | |
def hash_password | |
if password == password_confirm | |
password = hashed_password password | |
else | |
errors.add(:password, "The passwords do not match") | |
return false | |
end | |
end | |
def hashed_password password | |
Digest::SHA512.hexdigest("#{password}#{SALT}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment