1 class QuickvoteController < ApplicationController
8 @election = QuickVote.find_all(["name = ?", params[:votename]])[0]
11 @voter = QuickVoter.find_all(["session_id = ? and election_id = ?",
12 session.session_id, @election.id])[0]
14 @voter = QuickVoter.new
15 @voter.election = QuickVote.find_all( [ "name = ?", params[:votename] ] )[0]
18 redirect_to :controller => 'site'
24 @quickvote = QuickVote.new(params[:quickvote])
26 # store the candidate grabbed through ajax and stored in flash
27 @quickvote.candidatelist = flash[:candlist]
29 # try to save, if it fails, show the page again (the flash should
32 @quickvote = @quickvote.reload
33 render :action => 'success'
38 # if we don't have a quickvote param, it means that the person
39 # here has not been hitting this page and we can clear any
40 # candlist in the flash
41 flash.delete(:candlist) if flash.has_key?(:candlist)
46 candidate_name = params[:ajax][:newcandidate]
47 if flash.has_key?(:candlist) and flash[:candlist].instance_of?(Array)
48 flash[:candlist] << candidate_name
50 flash[:candlist] = [ candidate_name ]
53 render_partial 'candidate_list'
57 voter = QuickVoter.find_all(["session_id = ?", session.session_id])[0]
59 redirect_to quickvote_url( :votename => params[:votename] )
63 election = QuickVote.find_all(["name = ?", params[:votename]])[0]
65 if QuickVoter.find_all(["session_id = ? and election_id = ?",
66 session.session_id, election.id])[0]
67 flash[:notice] = "You have already voted!"
68 redirect_to quickvote_url( :votename => params[:votename] )
70 @voter = QuickVoter.new()
71 @voter.election = election
72 @voter.session_id = session.session_id
73 @voter.ipaddress = request.env["REMOTE_ADDR"]
77 @voter.vote = Vote.new
78 @voter.vote.votestring = params[:vote][:votestring]
80 render :action => 'thanks'
85 @election = QuickVote.find_all( ["name = ?", params[:votename]] )[0]
90 @election.voters.each do |voter|
91 plurality_tally << voter.vote.rankings.sort[0].candidate.id
92 approval_tally << voter.vote.rankings.sort[0..1].collect {|ranking| ranking.candidate.id}
93 preference_tally << voter.vote.rankings.sort.collect {|ranking| ranking.candidate.id}
96 @plurality_result = PluralityVote.new(plurality_tally).result
97 @approval_result = ApprovalVote.new(approval_tally).result
98 @condorcet_result = CloneproofSSDVote.new(preference_tally).result
99 @ssd_result = PureCondorcetVote.new(preference_tally).result
100 @borda_result = BordaVote.new(preference_tally).result
101 @runoff_result = InstantRunoffVote.new(preference_tally).result
104 @election.candidates.each {|c| @candidates[c.id] = c}