Skip to content

Instantly share code, notes, and snippets.

@coffeeaddict
Created April 6, 2011 19:47
Show Gist options
  • Save coffeeaddict/906371 to your computer and use it in GitHub Desktop.
Save coffeeaddict/906371 to your computer and use it in GitHub Desktop.
callbacks dont invalidate records
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