]> projects.mako.cc - selectricity/blob - app/models/candidate.rb
7af978afb3f95e422d035b780f4e4519f7fb8021
[selectricity] / app / models / candidate.rb
1 class Candidate < ActiveRecord::Base
2   belongs_to :election
3   validates_uniqueness_of :name
4
5   def <=>(other)
6     self.name <=> other.name 
7   end
8   
9   def to_s
10     name
11   end
12
13   def picture=(picture_field)
14     if picture_field
15       unless picture_field.content_type.match(/^image/)
16         return false
17       end
18       self.picture_filename = base_part_of(picture_field.original_filename)
19       self.picture_type =  picture_field.content_type.chomp
20       self.picture_data = picture_field.read
21     end
22   end
23
24   def base_part_of(filename)
25     name = File.basename(filename)
26     name.gsub(/[^\w._-]/, '')
27   end
28
29   def picture?
30     !self.picture_filename.nil?
31   end
32
33 end
34

Benjamin Mako Hill || Want to submit a patch?