Initital scaffolding of the website plus initial work on the adding and
[selectricity] / app / controllers / elections_controller.rb
diff --git a/app/controllers/elections_controller.rb b/app/controllers/elections_controller.rb
new file mode 100644 (file)
index 0000000..2b1f282
--- /dev/null
@@ -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

Benjamin Mako Hill || Want to submit a patch?