]> projects.mako.cc - selectricity/blob - app/models/election.rb
ba466b4b55928dac2f5291e0513d77b684a8c08d
[selectricity] / app / models / election.rb
1 class Election < ActiveRecord::Base
2   has_many :candidates
3   has_many :voters
4   has_many :votes
5   belongs_to :user
6   validates_presence_of :name, :description
7
8   require 'date'
9
10   def startdate
11     read_attribute( :startdate ) || DateTime.now
12   end
13
14   def enddate
15     read_attribute( :enddate ) || DateTime.now + 14
16   end
17
18   def destroy
19     self.candidates.each do |candidate|
20       candidate.destroy
21     end
22     super
23   end
24
25   def start_blockers
26     reasons = []
27     
28     if self.candidates.length <= 1
29       reasons << "You must have at least two candidates."
30     end
31     
32     if self.voters.length <= 1
33       reasons << "You must have at least two voters."
34     end
35
36     reasons
37   end
38
39   def activate!
40     self.active = 1
41   end
42
43 end

Benjamin Mako Hill || Want to submit a patch?