A few major changes:
[selectricity] / app / models / candidate.rb
1 class Candidate < ActiveRecord::Base
2   belongs_to :election
3   validates_uniqueness_of :name
4   validates_presence_of :name
5
6   def <=>(other)
7     self.name <=> other.name 
8   end
9   
10   def to_s
11     name
12   end
13
14   def picture=(picture_field)
15     if picture_field
16       unless picture_field.content_type.match(/^image/)
17         return false
18       end
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
22     end
23   end
24
25   def base_part_of(filename)
26     name = File.basename(filename)
27     name.gsub(/[^\w._-]/, '')
28   end
29
30   def picture?
31     !self.picture_filename.nil?
32   end
33
34 end
35

Benjamin Mako Hill || Want to submit a patch?