Fixed the detailed results so that they return anonymized results in
author<mako@atdot.cc> <>
Wed, 16 Aug 2006 04:51:17 +0000 (00:51 -0400)
committer<mako@atdot.cc> <>
Wed, 16 Aug 2006 04:51:17 +0000 (00:51 -0400)
aphabetical order and display vote information correct (as per tests at
least).

app/controllers/elections_controller.rb
app/models/candidate.rb
app/models/ranking.rb
app/views/elections/detailed_results.rhtml

index 339c77bc8991fe80ef38ab6afddd53e5ca53974d..4a85c293b5ea4b424cf78c852e39ca45496feaec 100644 (file)
@@ -105,12 +105,20 @@ class ElectionsController < ApplicationController
   
   def detailed_results
     @election = Election.find( params[:id] )
-    @voting_rolls = []
+
+    @voter_list = []
+    @vote_list = []
     @election.voters.each do |voter|
       if voter.vote and voter.vote.confirmed?
-        @voting_rolls << voter
+        @voter_list << voter.email
+       @vote_list << voter.vote
       end
     end
+
+    @vote_list.sort!
+    @vote_list.sort! { |a,b| a.token <=> b.token }
+    #breakpoint
+
   end
   
   private
index dfc8b1fec08fc19e87b320ea3a7c3856d1369c08..e17ba29b5f1ff866e3dd3c0d9c26beaa5b105aa5 100644 (file)
@@ -2,7 +2,7 @@ class Candidate < ActiveRecord::Base
   belongs_to :election
 
   def <=>(other)
-   self.name <=> other.name 
+    self.name <=> other.name 
   end
   
   def to_s
index 4b96b54c2060e5d8053c313a8975b901635e9042..ba021a92c5489369e75b92094ffe549ccf5c1730 100644 (file)
@@ -6,4 +6,8 @@ class Ranking < ActiveRecord::Base
     self.rank <=> other.rank
   end
 
+  def to_s
+    self.rank.to_s
+  end
+
 end
index 48296d6c667ce9608f60721fe115c5210b79ec25..cfb0e5a273c6f5e1a3738f01742b44511eed6adb 100644 (file)
@@ -1,29 +1,35 @@
-<p>The voting rolls for the last election are are follows.</p>
+<% %>
+
+<p>The voting rolls -- displayed here in alphabetical order -- for the
+last election are are follows.</p>
 
 <h2>Voters</h2>
 <table>
-<% for voter in @voting_rolls.randomize %>
+<% for email in @voter_list %>
 <tr>
-<td><%= voter.email %></td>
+<td><%= email %></td>
 </tr>
 <% end %>
 </table>
 
 <h2>Votes (by Token)</h2>
+
+<p>The votes, listed in alphabetical order by token.</p>
+
 <table border="1">
 <tr>
   <th rowspan="2">Token</th>
   <th colspan="<%= @election.candidates.length %>">Rank of Candidates</th>
 </tr>
 <tr>
-<% for candidate in @election.candidates.sort %>
+<% for candidate in @election.candidates.sort.reverse %>
   <th><%= candidate %></th>
 <% end %>
 </tr>
-<% for voter in @voting_rolls.randomize %>
+<% for vote in @vote_list %>
 <tr>
-<td><%= voter.vote.token %></td>
-<% for ranking in voter.vote %>
+<td><%= vote.token %></td>
+<% for ranking in vote.rankings %>
 <td><%= ranking %></td>
 <% end %>
 </tr>

Benjamin Mako Hill || Want to submit a patch?