1 class Candidate < ActiveRecord::Base
3 validates_presence_of :name
5 # validate uniqueness of a name *within a given election*
8 self.name <=> other.name
15 def picture=(picture_field)
17 unless picture_field.content_type.match(/^image/)
20 self.picture_filename = base_part_of(picture_field.original_filename)
21 self.picture_type = picture_field.content_type.chomp
22 self.picture_data = picture_field.read
26 def base_part_of(filename)
27 name = File.basename(filename)
28 name.gsub(/[^\w._-]/, '')
32 !self.picture_filename.nil?