2011-02-23 20:50:59 +00:00
|
|
|
class User < ActiveRecord::Base
|
2012-06-18 17:49:28 +00:00
|
|
|
# Include default devise modules. Others available are:
|
|
|
|
# :token_authenticatable, :confirmable,
|
|
|
|
# :lockable, :timeoutable and :omniauthable
|
2012-01-02 12:36:34 +00:00
|
|
|
devise :database_authenticatable, :registerable, :recoverable, :rememberable,
|
|
|
|
:trackable, :validatable
|
|
|
|
attr_accessible :address_1, :address_2, :city, :email, :name, :organization,
|
|
|
|
:password, :password_confirmation, :remember_me, :sms_number, :state,
|
|
|
|
:voice_number, :zip
|
2012-06-18 17:49:28 +00:00
|
|
|
validates_formatting_of :email, using: :email
|
|
|
|
validates_formatting_of :sms_number, using: :us_phone, allow_blank: true
|
|
|
|
validates_formatting_of :voice_number, using: :us_phone, allow_blank: true
|
|
|
|
validates_formatting_of :zip, using: :us_zip, allow_blank: true
|
2011-05-22 14:27:36 +00:00
|
|
|
validates_presence_of :name
|
2012-06-18 17:49:28 +00:00
|
|
|
has_many :reminders_to, class_name: "Reminder", foreign_key: "to_user_id"
|
|
|
|
has_many :reminders_from, class_name: "Reminder", foreign_key: "from_user_id"
|
2011-09-15 21:41:26 +00:00
|
|
|
has_many :things
|
2012-01-02 12:36:34 +00:00
|
|
|
before_validation :remove_non_digits_from_phone_numbers
|
|
|
|
def remove_non_digits_from_phone_numbers
|
|
|
|
self.sms_number = self.sms_number.to_s.gsub(/\D/, '').to_i if self.sms_number.present?
|
|
|
|
self.voice_number = self.voice_number.to_s.gsub(/\D/, '').to_i if self.voice_number.present?
|
|
|
|
end
|
2011-02-23 20:50:59 +00:00
|
|
|
end
|