Skip to content

Instantly share code, notes, and snippets.

@ruliana
Created May 11, 2012 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruliana/2657089 to your computer and use it in GitHub Desktop.
Save ruliana/2657089 to your computer and use it in GitHub Desktop.
Default values for models in Rails 3.0+
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