summaryrefslogtreecommitdiff
path: root/app/models/whitelist.rb
blob: 83037287ee08005eb34c5528b67fbe6e3a8a8717 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Whitelist < ActiveRecord::Base
  attr_accessible :name, :phone_numbers_attributes, :uuid

  belongs_to :whitelistable, :polymorphic => true
  
  # These are the phone_numbers for this whitelist.
  #
  has_many :phone_numbers, :as => :phone_numberable, :dependent => :destroy

  accepts_nested_attributes_for :phone_numbers, 
                                :reject_if => lambda { |phone_number| phone_number[:number].blank? }, 
                                :allow_destroy => true

  acts_as_list :scope => [ :whitelistable_type, :whitelistable_id ]

  validates_presence_of :uuid
  validates_uniqueness_of :uuid

  def to_s
    self.name || I18n.t('whitelists.name') + ' ID ' + self.id.to_s
  end

end