class Photo < ActiveRecord::Base
  belongs_to :actor
  validates_presence_of :description
  validates_format_of   :content_type, 
                        :with => /^image/,
  :message => "--- you can only upload images (i.e .jpg, .png, .gif etc.)"
  
  def validate 
     if self.date_taken > Date.today
       errors.add("Date taken cannot be in the future. ")
     end
  end 
                      
  def uploaded_photo=(photo_field)
    self.name         = base_part_of(photo_field.original_filename)
    self.content_type = photo_field.content_type.chomp
    self.data         = photo_field.read
  end
  
  def base_part_of(file_name)
    File.basename(file_name).gsub(/[^\w._-]/, '')
  end

end
  