frequency.rb 419 B

12345678910111213141516
  1. class Frequency < ActiveRecord::Base
  2. attr_accessible :delay, :description, :helpmsg, :name, :prefix, :activate
  3. # Relation
  4. has_many :bans, :dependent => :destroy, :inverse_of => :frequency
  5. accepts_nested_attributes_for :bans, :allow_destroy => true
  6. # Validation
  7. before_destroy :raise_if_last
  8. def raise_if_last
  9. if Frequency.count < 3
  10. raise "Can't delete last two frequencies"
  11. end
  12. end
  13. end