journalduhacker/app/models/invitation.rb

30 lines
535 B
Ruby
Raw Normal View History

2012-07-01 20:31:31 +02:00
class Invitation < ActiveRecord::Base
belongs_to :user
attr_accessible nil
2012-07-01 20:31:31 +02:00
validate do
if !email.to_s.match(/\A[^@ ]+@[^ @]+\.[^ @]+\z/)
2012-07-01 20:31:31 +02:00
errors.add(:email, "is not valid")
end
end
before_create :create_code
def create_code
(1...10).each do |tries|
if tries == 10
raise "too many hash collisions"
end
if !Invitation.find_by_code(self.code = Utils.random_str(15))
break
end
end
end
2012-07-03 18:59:50 +02:00
def send_email
InvitationMailer.invitation(self).deliver
2012-07-01 20:31:31 +02:00
end
end