class VideoFile < ActiveRecord::Base
  belongs_to :video_folder
  belongs_to :image_file
  
  def generate_token()
    begin
      self[:token] = SecureRandom.urlsafe_base64
    end while DataFile.exists?(:token => self[:token])
  end
  
  before_create { generate_token() }
  
  mount_uploader :poster, ImageUploader
  mount_uploader :mpg, VideoUploader
  mount_uploader :ogg, VideoUploader
  mount_uploader :webm, VideoUploader
  
  validates :title, :presence => true
  validates :slug, :presence => true, :uniqueness => true
  
  
  before_validation do
    
        
    
        if !self.slug?
    
          self.slug = self.title
  
      end
    
        self.slug = self.slug.to_slug
    
        #self.validate_permalink
  
    end
    
end
