Created
May 11, 2012 02:17
-
-
Save ruliana/2657089 to your computer and use it in GitHub Desktop.
Default values for models in Rails 3.0+
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 MyModel < ActiveRecord::Base | |
after_initialize :token_default_value | |
private | |
def token_default_value | |
self.token ||= UUID.new.generate | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment