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] )
105 def process_incoming_voters(raw_voter_list)
106 incoming_voters = RawVoterList.new( raw_voter_list )
108 unless incoming_voters.entries.empty?
109 incoming_voters.each do |new_voter|
111 if incoming_voters.email == 0
112 new_voter.contacted = 1
113 elsif incoming_voters.email == 1
114 email_voter( new_voter )
115 new_voter.contacted = 1
117 new_voter.contacted = 0
120 # the new voter should be in good shape. save add to the election
122 @election.voters << new_voter
126 # reset the next time to have a the same default value for emailing
127 @raw_voter_list = RawVoterList.new
128 @raw_voter_list.email = incoming_voters.email