2011-02-23 20:50:59 +00:00
|
|
|
class User < ActiveRecord::Base
|
2012-11-15 17:34:19 +00:00
|
|
|
include ActiveModel::ForbiddenAttributesProtection
|
2012-01-02 12:36:34 +00:00
|
|
|
devise :database_authenticatable, :registerable, :recoverable, :rememberable,
|
2014-04-01 08:15:29 +00:00
|
|
|
:trackable, :validatable
|
|
|
|
before_validation :remove_non_digits_from_phone_numbers
|
|
|
|
has_many :reminders_from, class_name: 'Reminder', foreign_key: 'from_user_id'
|
|
|
|
has_many :reminders_to, class_name: 'Reminder', foreign_key: 'to_user_id'
|
|
|
|
has_many :things
|
|
|
|
validates :name, presence: true
|
2014-03-25 09:47:44 +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
|
2014-04-01 08:15:29 +00:00
|
|
|
|
2012-01-02 12:36:34 +00:00
|
|
|
def remove_non_digits_from_phone_numbers
|
2014-04-01 08:15:29 +00:00
|
|
|
self.sms_number = sms_number.to_s.gsub(/\D/, '').to_i if sms_number.present?
|
|
|
|
self.voice_number = voice_number.to_s.gsub(/\D/, '').to_i if voice_number.present?
|
2012-01-02 12:36:34 +00:00
|
|
|
end
|
2011-02-23 20:50:59 +00:00
|
|
|
end
|