Sha256: 6983bccf1a729bc11a15e2e1175fcddd61a898063e9083e72495a46267d253d1

Contents?: true

Size: 965 Bytes

Versions: 2

Compression:

Stored size: 965 Bytes

Contents

class Contact < ActiveRecord::Base
  include Localized
  inheritable
  timestamps
  
  field :first_name
  field :second_name
  field :email
  field :text, :text
  field :read, :boolean, :default => false
  
  scope :unread, where("read IS NOT true")
  
  def name
    [first_name, second_name].compact.join(" ")
  end
  
  def unread?
    !read?
  end
  
  field :agreed_to_privacy, :boolean, :default => false
  validates_acceptance_of :agreed_to_privacy, :on => :create, :accept => true, :allow_nil => false
  validates_presence_of   :locale, :email, :first_name

  before_validation do |contact|
    contact.locale = I18n.locale.to_s
  end
  
  after_create do |contact|
    ContactsMailer.confirmation(contact).deliver
    ContactsMailer.notify(contact).deliver   
  end
  
  def read!
    unless read?
      update_attributes!(:read => true)      
    end
  end
  
  def unread!
    unless unread?
      update_attributes!(:read => false)
    end
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fullstack-contacts-0.1.4 lib/generators/fullstack/contacts/templates/app/models/contact.rb
fullstack-contacts-0.1.3 lib/generators/fullstack/contacts/templates/app/models/contact.rb