Skip to content

Instantly share code, notes, and snippets.

@patricklucas
Created January 14, 2011 02:14
Show Gist options
  • Save patricklucas/779046 to your computer and use it in GitHub Desktop.
Save patricklucas/779046 to your computer and use it in GitHub Desktop.
class EmailVerification < ActiveRecord::Base
belongs_to :user
before_validation :default_values
UUID_GEN = UUID::Client.new '/tmp/uuid.sock'
validates :user_id, :presence => true
def verify!
self.verified = true
end
private
def default_values
return unless new_record?
self.uuid ||= UUID_GEN.generate
self.verified ||= false
end
end
class User < ActiveRecord::Base
after_initialize :default_values
scope :byname, :order => 'lname'
scope :admins, :conditions => ['admin IS TRUE']
scope :clients, :conditions => ['admin IS FALSE']
acts_as_authentic
has_many :manifests
has_many :items
has_many :email_verifications
validates :fname, :presence => true
validates :lname, :presence => true
def name
[self.fname, self.lname].join ' '
end
def fullname
[self.lname, self.fname].join ', '
end
private
def default_values
return unless new_record?
self.admin ||= false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment