X-Git-Url: https://projects.mako.cc/source/selectricity/blobdiff_plain/cc4532dee83d19baf79b35fadf7064b9b5c3948a..1660465f3e072cbddc19b19f7f8869affb0694c5:/app/controllers/elections_controller.rb diff --git a/app/controllers/elections_controller.rb b/app/controllers/elections_controller.rb new file mode 100644 index 0000000..2b1f282 --- /dev/null +++ b/app/controllers/elections_controller.rb @@ -0,0 +1,73 @@ +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