Created
July 16, 2009 16:00
-
-
Save joshuaclayton/148498 to your computer and use it in GitHub Desktop.
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
# not all callbacks should be put in an observer, just things not directly associated with the model itself: | |
class UserObserver < ActiveRecord::Observer | |
def after_create(user) | |
ClearanceMailer::deliver_user_credentials(user) | |
end | |
end | |
# callbacks are still cool in AR models if it deals with the class itself | |
class User < ActiveRecord::Base | |
before_validation_on_create :generate_random_password, | |
:if => lambda {|user| user.password.blank? } | |
protected | |
def generate_random_password | |
self.password = self.password_confirmation = ActiveSupport::SecureRandom.hex(6) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment