Sha256: d51c43b7403d1f09cca38e90bd4f3ccaf8154939b87e7650ab4e78a500243b89

Contents?: true

Size: 703 Bytes

Versions: 3

Compression:

Stored size: 703 Bytes

Contents

class ContactUs::Contact
  include ActiveModel::Validations

  attr_accessor :email, :message

  validates :email,   :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i },
                      :presence => true
  validates :message, :presence => true

  def initialize(attributes = {})
    attributes.each do |key, value|
      self.send("#{key}=", value)
    end
    @attributes = attributes
  end

  def read_attribute_for_validation(key)
    @attributes[key]
  end

  def save
    if self.valid?
      ContactUs::ContactMailer.contact_email(self).deliver
      return true
    end
    return false
  end

  # To deal with the form, model must respond to #to_key
  def to_key; end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
contact_us-0.1.1 app/models/contact_us/contact.rb
contact_us-0.1.0 app/models/contact_us/contact.rb
contact_us-0.0.8 app/models/contact_us/contact.rb