1 class ElectionsController < ApplicationController
2 model :raw_voter_list, :voter, :vote, :candidate
5 # general methods for dealing with elections
8 render :action => 'list'
12 @election_pages, @elections = paginate :elections, :per_page => 10
15 # methods for displaying, creating, and manipulating election overview
18 @election = Election.find(params[:id])
22 @election = Election.new
26 @election = Election.find(params[:id])
30 @election = Election.new(params[:election])
32 flash[:notice] = 'Election was successfully created.'
33 redirect_to :action => 'new_candidates', :id => @election.id
35 render :action => 'new'
40 @election = Election.find(params[:id])
41 if @election.update_attributes(params[:election])
42 flash[:notice] = 'Election was successfully updated.'
43 redirect_to :action => 'show', :id => @election
45 render :action => 'edit'
50 election = Election.find(params[:id]).destroy
51 redirect_to :action => 'list'
54 # methods fod display, adding, deleting, and manipulating candidate
55 # information for elections
57 @election = Election.find( params[:id] )
61 election = Election.find( params[:id] )
62 @candidate = Candidate.new
63 @candidate.name = params[:newcandidate]
65 election.candidates << @candidate
66 render :partial => 'candidate_line'
70 candidate = Candidate.find( params[:id] )
75 @election = Election.find( params[:id] )
78 # methods for displaying, adding, deleting, and manipulating voters
79 # for a particular election
81 @election = Election.find( params[:id] )
82 if params.has_key?[:raw_voter_list]
83 process_incoming_voters( params[:raw_voter_list] )
85 @raw_voter_list = RawVoterList.new
90 @election = Election.find( params[:id] )
91 if params.has_key?( :raw_voter_list )
92 process_incoming_voters( params[:raw_voter_list] )
95 @raw_voter_list = RawVoterList.new
99 voter = Voter.find( params[:id] )
107 @election = Election.find( params[:id] )
109 @election.voters.each do |voter|
110 if voter.vote and voter.vote.confirmed?
111 @voting_rolls << voter
120 def process_incoming_voters(raw_voter_list)
121 incoming_voters = RawVoterList.new( raw_voter_list )
123 unless incoming_voters.entries.empty?
124 incoming_voters.each do |new_voter|
126 if incoming_voters.email == 0
127 new_voter.contacted = 1
128 elsif incoming_voters.email == 1
129 email_voter( new_voter )
130 new_voter.contacted = 1
132 new_voter.contacted = 0
135 # the new voter should be in good shape. save add to the election
137 @election.voters << new_voter
141 # reset the next time to have a the same default value for emailing
142 @raw_voter_list = RawVoterList.new
143 @raw_voter_list.email = incoming_voters.email