1 class Vote < ActiveRecord::Base
2 # relationships to other classes
8 after_update :save_rankings
9 before_destroy :destroy_rankings
16 votes.each {|vote| yield vote}
24 @votes = rankings.sort.collect { |ranking| ranking.candidate.id }
37 self.votes.each_with_index do |candidate, index|
40 ranking.candidate = Candidate.find(candidate)
41 self.rankings << ranking
46 rankings.each { |ranking| ranking.destroy }
53 unless self.voter.election.quickvote?
54 token.destroy and token.reload if token
55 self.token = Token.new
64 def votestring=(string="")
65 candidate_ids = voter.election.candidates.sort.collect \
66 { |candidate| candidate.id.to_i }
68 rel_votes = string.split("").collect { |vote| vote.to_i }
70 # covert relative orders to absolute candidate ids
71 self.votes = rel_votes.collect { |vote| candidate_ids[ vote - 1 ] }