if rankings.empty?
@votes = Array.new
else
- @votes = rankings.sort.collect { |ranking| ranking.candidate.id }
+ @votes = self.rankings.sort.collect { |ranking| ranking.candidate.id }
end
end
end
def save_rankings
+ self.votes # i need to initalize this before destroying rankings
+ # or else the ranks themselves show up as nil
+
destroy_rankings
self.votes.each_with_index do |candidate_id, index|
ranking = Ranking.new
end
def confirm!
- self.confirmed = 1
- self.time = Time.now
- self.save
-
- unless self.voter.election.quickvote?
- token.destroy and token.reload if token
- self.token = Token.new
+ if self.voter.election.candidates.length == self.rankings.length
+ self.confirmed = 1
+ self.time = Time.now
self.save
+
+ unless self.voter.election.quickvote?
+ token.destroy and token.reload if token
+ self.token = Token.new
+ self.save
+ end
+ return false
+ else
+ return true
end
end