Changed quickvotes so that they take an identifier as opposed to just a
author<mako@atdot.cc> <>
Tue, 14 Aug 2007 18:56:32 +0000 (14:56 -0400)
committer<mako@atdot.cc> <>
Tue, 14 Aug 2007 18:56:32 +0000 (14:56 -0400)
votename. This identifier may be either just a votename or an integer id.

app/controllers/quickvote_controller.rb
app/views/quickvote/index.rhtml
app/views/quickvote/success.rhtml
app/views/quickvote/thanks.rhtml
app/views/site/index.rhtml
app/views/voter/_vote.rhtml
config/routes.rb

index 0b745af72e13c79548b227ff83174a79660e9b94..f5ab58128caa2d0a8ae03a67fa9994ab0119a2ed 100644 (file)
@@ -49,7 +49,7 @@ class QuickvoteController < ApplicationController
   #############################################################
 
   def index
-    @election = QuickVote.find_all(["name = ?", params[:votename]])[0]
+    @election = ident_to_quickvote(params[:ident])
     
     # if the person has specified an election, we show them the voting
     # page. otherwise, we redirect back to main the page
@@ -71,7 +71,7 @@ class QuickvoteController < ApplicationController
       unless @voter
         # create a new voter and populate it
         @voter = QuickVoter.new
-        @voter.election = QuickVote.find_all( [ "name = ?", params[:votename] ] )[0]
+        @voter.election = @election
         @voter.session_id = session.session_id
         
              # create new vote and make it the defaulted sorted list
@@ -87,7 +87,7 @@ class QuickvoteController < ApplicationController
 
   def confirm
     # we need the election to verify that we have the right voter
-    election = QuickVote.find_all( [ "name = ?", params[:votename] ] )[0]
+    election = ident_to_quickvote(params[:ident])
 
     # find out who the voter is for this election
     @voter = QuickVoter.find_all(["session_id = ? and election_id = ?", 
@@ -96,12 +96,12 @@ class QuickvoteController < ApplicationController
     if not @voter
       # we have not seen this  voter before. something is wrong, try
       # again
-      redirect_to quickvote_url( :votename => params[:votename] ) 
+      redirect_to quickvote_url( :ident => params[:ident] ) 
       
     elsif @voter.voted? 
       # this person has already voted, we try again
       flash[:notice] = "You have already voted!"
-      redirect_to quickvote_url( :votename => params[:votename] )
+      redirect_to quickvote_url( :ident => params[:ident] )
       
     else
       # record the ip address for posterity
@@ -122,7 +122,7 @@ class QuickvoteController < ApplicationController
   def change
     voter = QuickVoter.find_all(["session_id = ?", session.session_id])[0]
     voter.destroy
-    redirect_to quickvote_url( :votename => params[:votename] )
+    redirect_to quickvote_url( :ident => params[:ident] )
   end
 
   def sort_candidates
@@ -142,7 +142,7 @@ class QuickvoteController < ApplicationController
   ###############################################################
 
   def results
-    @election = QuickVote.find_all(["name = ?", params[:votename]] )[0]
+    @election = ident_to_quickvote(params[:ident])
 
     # initalize the tallies to empty arrays
     preference_tally = Array.new
@@ -173,4 +173,15 @@ class QuickvoteController < ApplicationController
     @election.candidates.each {|c| @candidates[c.id] = c}
   end
 
+  private
+  def ident_to_quickvote(ident)
+    if ident.match(/^\d+$/)
+      quickvote = QuickVote.find(ident)
+    else
+      quickvote = QuickVote.find_all(["name = ?", ident])[0]
+    end
+
+    return quickvote
+  end
+
 end
index eb378456c3def1c16b3ef2b2a4e85e5940755552..e7cac3d88f13de8d89892e233a4de5e192f7522e 100644 (file)
@@ -17,9 +17,9 @@
   <p>You have already voted. You can:</p>
   
   <ul>
-    <li><%= link_to "Change your vote.", quickaction_url( :votename => @voter.election.name, :action => 'change' ) %></li>
+    <li><%= link_to "Change your vote.", quickaction_url( :ident => @voter.election.name, :action => 'change' ) %></li>
 
-    <li><%= link_to "View election results.", quickaction_url( :votename => @voter.election.name, :action => 'results' ) %></li>
+    <li><%= link_to "View election results.", quickaction_url( :ident => @voter.election.name, :action => 'results' ) %></li>
   </ul>
 <% else %>
 
@@ -38,7 +38,7 @@ bottom</em>. When you are done, press confirm to record your vote.</p>
 
 <div class="clearbox"></div>
 
-<%= button_to "Confirm Vote", quickaction_url( :action => 'confirm', :votename => @voter.election.name)  %>
+<%= button_to "Confirm Vote", quickaction_url( :action => 'confirm', :ident => @voter.election.name)  %>
 
 <%= sortable_element 'rankings-list',
     :url => { :action => "sort_candidates" , :id => @voter.vote.id },
index d793a7ab6f089be0a4e380f452dfbc15ab5f7c89..8d2baf6a0e06d579a7c3c08c32553a4caeaefa12 100644 (file)
@@ -4,7 +4,7 @@
 <p>Please direct voters to:</p>
 
 <blockquote><strong>
-  <%= quickvote_url( :votename => @quickvote.name ) -%>
+  <%= quickvote_url( :ident => @quickvote.name ) -%>
 </strong></blockquote>
 
 <p>This vote will end on <em><%= @quickvote.enddate.strftime('%A, %B %d, %Y') %></em></p>
@@ -13,4 +13,4 @@
 HyperChad site. Voters do not need to log in or authenticate to
 participate in this election.</p>
 
-<p><%= link_to "Jump to QuickVote", quickvote_url( :votename => @quickvote.name ) %></p>
+<p><%= link_to "Jump to QuickVote", quickvote_url( :ident => @quickvote.name ) %></p>
index 72cfe61fa490af535a5e59bea65f487cd1b7f931..1975eb705162f592c259219e0143c87e4f046bcb 100644 (file)
@@ -12,9 +12,9 @@ preferences:</p>
 <p>Thanks you voting! You can:</p>
 
 <ul>
-  <li><%= link_to "Change Your Vote", quickaction_url( :votename => @voter.election.name, :action => 'change' ) %></li>
+  <li><%= link_to "Change Your Vote", quickaction_url( :ident => @voter.election.name, :action => 'change' ) %></li>
 
-  <li><%= link_to "View Current Results", quickaction_url( :votename => @voter.election.name, :action => 'results' ) %></li>
+  <li><%= link_to "View Current Results", quickaction_url( :ident => @voter.election.name, :action => 'results' ) %></li>
 </ul>
 
 
index eb009b31db9a155f2bbfe29113e3e25368b73238..0d59849a6997d2c621454e2491cca25284e3ed82 100644 (file)
@@ -17,7 +17,7 @@ methods.</p>
 
 <ul>
 <% for quickvote in @quickvotes %>
-<li><%= link_to (quickvote.shortdesc || "Unnamed"), quickvote_url(:votename => quickvote.name) %></li>
+<li><%= link_to (quickvote.shortdesc || "Unnamed"), quickvote_url(:ident => quickvote.name) %></li>
 <% end %>
 </ul>
 
index dc240af61ea0d3e81e308f3c6db2dd36c0bdb37c..d1447916c846451b64d19d05e580411977f12bc0 100644 (file)
@@ -12,7 +12,7 @@ least preferred. Please list <em>all</em> choices in every vote.
 <em>(For example, 123 or 321 or 213, etc.)</em></p>
 
 <% if @voter.election.quickvote? %>
-  <%= form_tag quickaction_url( :votename => @voter.election.name, :action => 'confirm') %>
+  <%= form_tag quickaction_url( :ident => @voter.election.name, :action => 'confirm') %>
 <% else %>
   <%= form_tag :action => 'review', :id => @voter.password %>
 <% end %>
index ee64eabaa4a50025e4a467d04ade5b11a782d1b9..96beafd4dde7af51ba160cde5e02fff5794c7dd0 100644 (file)
@@ -17,11 +17,11 @@ ActionController::Routing::Routes.draw do |map|
                :controller => 'quickvote',
                :requirements => { :action => /(create|add_candidate|sort_candidates)/ }
 
-  map.quickaction 'quickvote/:votename/:action',
+  map.quickaction 'quickvote/:ident/:action',
                   :controller => 'quickvote',
                        :requirements => { :action => /(change|confirm|results)/ }
 
-  map.quickvote 'quickvote/:votename',
+  map.quickvote 'quickvote/:ident',
                 :controller => 'quickvote', :action => 'index'
 
   # Allow downloading Web Service WSDL as a file with an extension

Benjamin Mako Hill || Want to submit a patch?