Sha256: 849a24e8003e42dab8b758b205106e2a4fad56ba88bbd3f5a3c755a362f30e97

Contents?: true

Size: 777 Bytes

Versions: 4

Compression:

Stored size: 777 Bytes

Contents

class ContactUs::Contact
  include ActiveModel::Conversion
  include ActiveModel::Validations

  attr_accessor :email, :message, :name, :subject

  validates :email,   :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i },
                      :presence => true
  validates :message, :presence => true
  validates :name,    :presence => {:if => Proc.new{ContactUs.require_name}}
  validates :subject, :presence => {:if => Proc.new{ContactUs.require_subject}}

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

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

  def persisted?
    false
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
contact_us-1.2.0 app/models/contact_us/contact.rb
contact_us-1.1.0 app/models/contact_us/contact.rb
contact_us-1.0.1 app/models/contact_us/contact.rb
contact_us-1.0.0 app/models/contact_us/contact.rb