--- /dev/null
+class ElectionsController < ApplicationController
+ def index
+ list
+ render :action => 'list'
+ end
+
+ def list
+ @election_pages, @elections = paginate :elections, :per_page => 10
+ end
+
+ def show
+ @election = Election.find(params[:id])
+ end
+
+ def new
+ @election = Election.new
+ end
+
+ def create_election
+ @election = Election.new(params[:election])
+ if @election.save
+ flash[:notice] = 'Election was successfully created.'
+ redirect_to :action => 'new_candidates', :id => @election.id
+ else
+ render :action => 'new'
+ end
+ end
+
+ def new_candidates
+ @election = Election.find( params[:id] )
+ end
+
+ def add_candidate
+ election = Election.find( params[:id] )
+ @candidate = Candidate.new
+ @candidate.name = params[:newcandidate]
+ @candidate.save
+ election.candidates << @candidate
+ render :partial => 'candidate_line'
+ end
+
+ def delete_candidate
+ candidate = Candidate.find( params[:id] )
+ candidate.destroy
+ end
+
+ def edit
+ @election = Election.find(params[:id])
+ end
+
+ def edit_candidates
+ @election = Election.find( params[:id] )
+ end
+
+ def edit_voters
+ @election = Election.find( params[:id] )
+ end
+
+ def update
+ @election = Election.find(params[:id])
+ if @election.update_attributes(params[:election])
+ flash[:notice] = 'Election was successfully updated.'
+ redirect_to :action => 'show', :id => @election
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ election = Election.find(params[:id]).destroy
+ redirect_to :action => 'list'
+ end
+end