I have a rail model Userthat has fields name, emailand hash.
I save the data in this:
@u = User.create(:name=>'test', :email=>"test@mail.com")
@u.save
How can I enable the callback before_createso that the hash value gets the hash string by the following code before saving the record:
Digest::SHA1.hexdigest('something secret' + email)
What will my model look like User?
class Employee < ActiveRecord::Base
before_create :set_hash
def set_hash
//what goes in here?
end
end
source
share