1 class Candidate < ActiveRecord::Base
3 validates_uniqueness_of :name
4 validates_presence_of :name
7 self.name <=> other.name
14 def picture=(picture_field)
16 unless picture_field.content_type.match(/^image/)
19 self.picture_filename = base_part_of(picture_field.original_filename)
20 self.picture_type = picture_field.content_type.chomp
21 self.picture_data = picture_field.read
25 def base_part_of(filename)
26 name = File.basename(filename)
27 name.gsub(/[^\w._-]/, '')
31 !self.picture_filename.nil?