Skip to content

Instantly share code, notes, and snippets.

@alanjcfs
Created September 12, 2012 00:57
Show Gist options
  • Save alanjcfs/3703386 to your computer and use it in GitHub Desktop.
Save alanjcfs/3703386 to your computer and use it in GitHub Desktop.
User
class Client < ActiveRecord::Base
attr_accessible :first_name, :last_name, :middle_initial, :suffix,
:email, :email_2, :phone, :using, :phone_2, :using_2,
:age_group, :communication_types, :funder,
:street_address, :street_address_2, :city, :county, :zip_code, :state,
:permission_to_photograph, :mailing_list, :email_or_letter,
:notes
validates :first_name, presence: true, length: { maximum: 15 }
validates :last_name, presence: true, length: { maximum: 15 }
validates :middle_initial, allow_blank: true, length: { maximum: 15 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
# before_save { self.phone.gsub(/\D/, '') }
# before_save { self.zip_code.gsub(/\D/, '') }
# before_save { self.state.upcase! }
validates_length_of :phone, :is => 10
validates_length_of :phone_2, :is => 10, :allow_blank => true
with_options :if => :full_intake? do |l|
l.validates :street_address, presence: true, length: { maximum: 25 }
l.validates_length_of :street_address_2, :in => 5..25, :allow_blank => true
l.validates_length_of :zip_code, :is => 5
l.validates_length_of :state, :is => 2
end
def name
"#{first_name} #{last_name}"
end
def full_name
"#{first_name} #{middle_initial}. #{last_name} #{suffix}"
end
def full_intake?
self.full_intake
end
end
class CreateClients < ActiveRecord::Migration
def change
create_table :clients do |t|
t.integer :user_id
# Identification
t.string :first_name
t.string :last_name
t.string :middle_initial
t.string :suffix
# Contact Information
t.string :email
t.string :email_2
t.string :phone
t.string :using # vp, voice, text
t.string :phone_2
t.string :using_2
# Quick Intake Reporting
t.boolean :age_group # adulthood
t.string :communication_types # deaf, deaf-blind, etc.
t.string :funder
# Address
t.string :street_address
t.string :street_address_2
t.string :city
t.string :county
t.integer :zip_code
t.string :state
# Miscellaneous
t.boolean :permission_to_photograph
t.boolean :mailing_list
t.string :preferred_contact
t.boolean :full_intake, default: false
t.string :status # active, deceased, moved away
t.text :notes
t.timestamps
end
add_index :clients, [:created_at, :user_id]
end
end
class CreateFullIntakes < ActiveRecord::Migration
def change
create_table :full_intakes do |t|
t.integer :client_id
t.integer :user_id
# Demographics Information
t.date :birthdate
t.boolean :adulthood
t.string :sex
t.string :residential_status
t.string :ethnicity
t.boolean :female_head_of_household
t.integer :household_size
t.integer :income
t.string :education
# Referrals
t.integer :initial_contact # Using integer or string?
t.integer :referral # Add index/foreign key to find?
# Employment Development Department
t.string :ssn
t.timestamps
end
add_index :full_intakes, [:created_at, :user_id]
end
end
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :first_name # (originally one name, last first)
t.string :last_name
t.string :department # DSS, EDD, etc.
t.string :level # Director, StaffMember, Contractor, Job Developer, etc.
t.string :supervisor
t.string :status # Active, Inactive
t.string :email
t.string :password_digest
t.string :remember_token
t.boolean :admin, default: false
t.timestamps
end
add_index :users, :email, unique: true
add_index :users, :remember_token
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment