class Inscrit < ActiveRecord::Base before_validation :verify validates_presence_of :email validates_uniqueness_of :email validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i has_many :inscrit_newsgroups has_many :newsgroups, :through => :inscrit_newsgroups protected def verify(size=16) if !self.verify_key s = "" size.times { s << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr } self.verify_key = s end end end