class ContactMessage < ActiveRecord::Base
  
  # Accessors
  attr_accessible :email, :message, :name, :phone
  
  # Validations
  validates :email, :presence => true, :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
  validates :message, :name, :presence => true
  
  # Callbacks
  after_save :deliver_contact_email

  # Acts as TextCaptcha
  acts_as_textcaptcha

  # Methods used on callbacks
  def deliver_contact_email
    UserMailer.new_contact_message(self).deliver
  end
  
end
