X-Git-Url: https://projects.mako.cc/source/selectricity-live/blobdiff_plain/9abed97635edbac7fb1a687298fff5c5434cdff4..75091532075247ae9c47164ea883f4fe803eddf4:/app/models/election.rb diff --git a/app/models/election.rb b/app/models/election.rb index 61286e1..0860a42 100644 --- a/app/models/election.rb +++ b/app/models/election.rb @@ -2,6 +2,7 @@ class Election < ActiveRecord::Base has_many :candidates has_many :voters has_many :votes + belongs_to :user validates_presence_of :name, :description require 'date' @@ -20,5 +21,27 @@ class Election < ActiveRecord::Base end super end + + def start_blockers + reasons = [] + + if self.candidates.length <= 1 + reasons << "You must have at least two candidates." + end + + if self.voters.length <= 1 + reasons << "You must have at least two voters." + end + + reasons + end + + def activate! + self.active = 1 + end + def quickvote? + quickvote.to_i == 1 + end + end