1 class Vote < ActiveRecord::Base
10 def votestring=(string="")
11 rel_votes = string.split("").collect { |vote| vote.to_i }
13 # covert relative orders to absolute candidate ids
14 candidate_ids = voter.election.candidates.sort
15 candidate_ids.collect! { |candidate| candidate.id.to_i }
17 rel_votes.collect! { |vote| candidate_ids[ vote - 1 ] }
22 rankings.each { destroy } unless rankings.empty?
23 @votes.each_with_index do |candidate, index|
25 ranking.rank = index + 1
26 ranking.candidate = Candidate.find(candidate)
27 self.rankings << ranking
34 rankings.each { destroy }