From: New candidate name: Candidate picture (optional and < 100x100 pixels): There are currently no voters registered for this election. The following voters are currently registered for this election: Please enter a list of new email addresses of potential voters. Please enter a list of new email addresses of voters (one email
+address per line)." + email.encoded + "
")
+ breakpoint
+ break
+ end
+
+ #@election.activate!
end
# methods fod display, adding, deleting, and manipulating candidate
@@ -97,12 +105,12 @@ class ElectionController < ApplicationController
def update_candidate
@candidate = Candidate.find(params[:id])
+ @election = @candidate.election
if @candidate.update_attributes(params[:candidate])
- flash[:notice] = 'Candidate information was successfully updated.'
- redirect_to :action => 'edit_candidates', :id => @candidate.election
+ redirect_to :action => 'edit_candidates', :id => @candidate.election.id
else
- render :action => 'edit_candidates'
+ render :action => 'edit_candidate'
end
end
diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb
index 8d2f8b2..f2eb153 100644
--- a/app/controllers/site_controller.rb
+++ b/app/controllers/site_controller.rb
@@ -3,10 +3,11 @@ class SiteController < ApplicationController
model :user, :election
def index
- @current_elections = session[:user].elections.sort do |a,b|
- b.enddate <=> a.enddate
+ if session[:user]
+ session[:user] = User.find(session[:user].id)
+ @current_elections = session[:user].elections.sort do |a,b|
+ b.enddate <=> a.enddate
+ end
end
-
-
end
end
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index f88f7d5..25f827c 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -1,3 +1,8 @@
class UserController < ApplicationController
layout 'vb'
+
+ def home
+ redirect_to :controller => 'site', :action => 'index'
+ end
+
end
diff --git a/app/models/candidate.rb b/app/models/candidate.rb
index 7af978a..7b6e802 100644
--- a/app/models/candidate.rb
+++ b/app/models/candidate.rb
@@ -1,6 +1,7 @@
class Candidate < ActiveRecord::Base
belongs_to :election
validates_uniqueness_of :name
+ validates_presence_of :name
def <=>(other)
self.name <=> other.name
diff --git a/app/models/election.rb b/app/models/election.rb
index 69038e4..ba466b4 100644
--- a/app/models/election.rb
+++ b/app/models/election.rb
@@ -21,5 +21,23 @@ class Election < ActiveRecord::Base
end
super
end
-
+
+ def start_blockers
+ reasons = []
+
+ if self.candidates.length <= 1
+ reasons << "You must have at least two candidates."
+ end
+
+ if self.voters.length <= 1
+ reasons << "You must have at least two voters."
+ end
+
+ reasons
+ end
+
+ def activate!
+ self.active = 1
+ end
+
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 62c5d1d..4f25e06 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,5 +1,6 @@
class User < ActiveRecord::Base
include LoginEngine::AuthenticatedUser
+
has_many :elections
def name
diff --git a/app/models/voter.rb b/app/models/voter.rb
index e9b3e9e..c4700cb 100644
--- a/app/models/voter.rb
+++ b/app/models/voter.rb
@@ -2,11 +2,12 @@ class Voter < ActiveRecord::Base
belongs_to :election
has_one :vote
- def initialize(args)
- super(args)
-
+ before_create :create_password
+
+ def create_password
token_generator = UniqueTokenGenerator.new( 16 )
- until password and Voter.find_all( [ "password = ?", password ]).empty?
+ until password and not password.empty? \
+ and Voter.find_all( [ "password = ?", password ]).empty?
self.password = token_generator.token
end
end
diff --git a/app/models/voter_notify.rb b/app/models/voter_notify.rb
new file mode 100644
index 0000000..09f7899
--- /dev/null
+++ b/app/models/voter_notify.rb
@@ -0,0 +1,14 @@
+class VoterNotify < ActionMailer::Base
+
+ def votestart(voter)
+ @subject = "[%s] Election In Progress!" % voter.election.name
+ @recipients = voter.email
+ @from = MAIL_CONFIG[:from]
+ @sent_on = Time.now
+ @body = { :voter => voter }
+ end
+
+ def reminder(voter)
+ end
+
+end
diff --git a/app/views/election/_candidate_form.rhtml b/app/views/election/_candidate_form.rhtml
index e9770b8..6e0fb1f 100644
--- a/app/views/election/_candidate_form.rhtml
+++ b/app/views/election/_candidate_form.rhtml
@@ -1,3 +1,5 @@
+<% %>
+
<%= text_field :candidate, :name %>
<%= file_field :candidate, :picture %>
@@ -16,4 +18,4 @@
<% end %>
-
+<% end %>
diff --git a/app/views/election/_voters_form.rhtml b/app/views/election/_voters_form.rhtml
index 620b508..3b01c00 100644
--- a/app/views/election/_voters_form.rhtml
+++ b/app/views/election/_voters_form.rhtml
@@ -1,10 +1,13 @@
-
The following are valid options or candidates in this election:
@@ -11,6 +13,13 @@ <% else %>There are no candidates registered for this election.
<% end %> +Please enter new candidates below.
-<%= render :partial => 'candidates_form' %> + +<%= form_tag( { :action => :add_candidate, :id => @election.id }, + :multipart => true ) %> +<%= render :partial => 'candidate_form' %> +<%= submit_tag "Add Candidate" %> +<%= end_form_tag %> + <%= button_to "Done!", :action => 'show', :id => @election %> diff --git a/app/views/election/show.rhtml b/app/views/election/show.rhtml index f389059..90c93ea 100644 --- a/app/views/election/show.rhtml +++ b/app/views/election/show.rhtml @@ -32,7 +32,36 @@ <% unless @election.voters.empty? %> <%= render :partial => 'voter_list' %> + <%= link_to "Add or remove voters.", :action => 'edit_voters', :id => @election.id %> <% else %>There are currently no voters registered for this election. <%= link_to "Add some!", :action => 'edit_voters', :id => @election.id %>
<% end %> + +Your election cannot be started for the following reasons:
+Please check eveything carefully on this page before starting this +election. Once you begin the election, you will not be able to +add or change candidates, modify the voting lists, or change the +election end time.
+ +When you begin the election, the following will happen:
+ +