]> projects.mako.cc - selectricity/blob - app/models/candidate.rb
Merge trunk
[selectricity] / app / models / candidate.rb
1 class Candidate < ActiveRecord::Base
2   belongs_to :election
3   validates_presence_of :name
4
5   # i have to call this picture_assoc because picture= does not overload
6   # the normal association method made by has_one
7   has_one :picture_obj, :class_name => "Picture"
8
9   # validate uniqueness of a name *within a given election*
10
11   def <=>(other)
12     self.name <=> other.name 
13   end
14   
15   def to_s
16     name
17   end
18
19   def picture
20     picture_obj
21   end
22
23   def picture=(field)
24     if field and field.length > 0
25       self.picture_obj = Picture.new.set_from_field(field)
26       return picture_obj.save
27     else
28       return false
29     end
30   end
31
32   def picture?
33     !self.picture_obj.nil?
34   end
35
36 end
37

Benjamin Mako Hill || Want to submit a patch?