From 269c76d5c3935d915a15dd8e9167321bdea5faf0 Mon Sep 17 00:00:00 2001 From: Date: Fri, 9 May 2008 19:12:17 -0400 Subject: [PATCH] elections marked as viewable will now dispaly a link to their results page while the election is on going, but not if there haven't been any voters. --- app/controllers/election_controller.rb | 6 ++++-- app/views/election/show.rhtml | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/controllers/election_controller.rb b/app/controllers/election_controller.rb index bfef021..571b936 100644 --- a/app/controllers/election_controller.rb +++ b/app/controllers/election_controller.rb @@ -173,7 +173,7 @@ class ElectionController < ApplicationController def results @election = Election.find( params[:id] ) votes = [] - + @election.voters.each do |voter| if voter.vote and voter.vote.confirmed? votes << voter.vote.rankings.sort.collect {|vote| vote.candidate_id} @@ -186,6 +186,7 @@ class ElectionController < ApplicationController @candidates_by_id = {} @election.candidates.each {|cand| @candidates_by_id[cand.id] = cand} + end def detailed_results @@ -194,7 +195,8 @@ class ElectionController < ApplicationController @voter_list = [] @vote_list = [] - @election.voters. each do |voter| + + @election.voters.each do |voter| if voter.vote and voter.vote.confirmed? @voter_list << voter.email @vote_list << voter.vote diff --git a/app/views/election/show.rhtml b/app/views/election/show.rhtml index 5a46af9..6060fb1 100644 --- a/app/views/election/show.rhtml +++ b/app/views/election/show.rhtml @@ -3,12 +3,24 @@ -<% if @election.active? %> +<% if @election.done? %> +
Election is finished. <%= link_to "View results", + :action => 'detailed_results', :id => @election.id %>.
+ +<% elsif (@election.active? && @election.viewable?) %> +
The creator of this election has decided that the results + should be viewable while the election is in progress. + <%if @election.voters.empty? %> + However, no one has voted yet. + <% else %> + <%= link_to "View results", :action => 'detailed_results', + :id => @election.id %>. + <% end %> +
+<% elsif @election.active? %>
Vote is in currently in progress. Return to this page for results on <%= @election.enddate %>.
-<% elsif @election.done? %> -
Election is finished. <%= link_to "View results", - :action => 'results', :id => @election.id %>.
+ <% else %>

<%= link_to "Edit General Information", @@ -41,7 +53,7 @@ -<% unless @election.authenticated -%> +<% if @election.active? and not @election.authenticated? %>

Link

<%= (link_to ("Go Vote!", :controller => 'voter', :action => 'index', :election_id => @election.id)).to_s %> -- 2.30.2