room.rb 486 B

1234567891011121314151617181920
  1. class Room < ActiveRecord::Base
  2. include SecretAccessible
  3. has_many :clients
  4. has_many :messages , :dependent => :destroy
  5. validates_presence_of :is_public , :secret
  6. validates_uniqueness_of :secret
  7. before_validation :assign_secret
  8. def self.all_empty ; self.all.select { | room | room.clients.size == 0 } ; end ;
  9. def clients_csv ; (self.clients.map { | client | client.name }).join ',' ; end ;
  10. private
  11. def assign_secret ; self.secret = generate_secret ; end ;
  12. end