Initital scaffolding of the website plus initial work on the adding and
[selectricity] / app / controllers / elections_controller.rb
1 class ElectionsController < ApplicationController
2   def index
3     list
4     render :action => 'list'
5   end
6
7   def list
8     @election_pages, @elections = paginate :elections, :per_page => 10
9   end
10
11   def show
12     @election = Election.find(params[:id])
13   end
14
15   def new
16     @election = Election.new
17   end
18
19   def create_election
20     @election = Election.new(params[:election])
21     if @election.save
22       flash[:notice] = 'Election was successfully created.'
23       redirect_to :action => 'new_candidates', :id => @election.id
24     else
25       render :action => 'new'
26     end
27   end
28
29   def new_candidates
30     @election = Election.find( params[:id] )
31   end
32
33   def add_candidate
34     election = Election.find( params[:id] )
35     @candidate = Candidate.new
36     @candidate.name = params[:newcandidate] 
37     @candidate.save
38     election.candidates << @candidate
39     render :partial => 'candidate_line'
40   end
41   
42   def delete_candidate
43     candidate = Candidate.find( params[:id] )
44     candidate.destroy
45   end
46
47   def edit
48     @election = Election.find(params[:id])
49   end
50
51   def edit_candidates
52     @election = Election.find( params[:id] )
53   end
54   
55   def edit_voters
56     @election = Election.find( params[:id] )
57   end
58   
59   def update
60     @election = Election.find(params[:id])
61     if @election.update_attributes(params[:election])
62       flash[:notice] = 'Election was successfully updated.'
63       redirect_to :action => 'show', :id => @election
64     else
65       render :action => 'edit'
66     end
67   end
68
69   def destroy
70     election = Election.find(params[:id]).destroy
71     redirect_to :action => 'list'
72   end
73 end

Benjamin Mako Hill || Want to submit a patch?