@election.voters.each do |voter|
email = VoterNotify.create_votestart(voter)
render(:text => "<pre>" + email.encoded + "</pre>")
- breakpoint
- break
end
#@election.activate!
end
end
end
+
+ def create_quickvote
+ if params[:quickvote]
+ @quickvote = QuickVote.new(params[:quickvote])
+ if @quickvote.reviewed? and @quickvote.save
+ @quickvote = @quickvote.reload
+ render :action => 'success_quickvote'
+ end
+ end
+ end
+
end
class Candidate < ActiveRecord::Base
belongs_to :election
- validates_uniqueness_of :name
validates_presence_of :name
+ # validate uniqueness of a name *within a given election*
+
def <=>(other)
self.name <=> other.name
end
--- /dev/null
+class QuickVote < Election
+ after_validation :create_candidates
+ validates_uniqueness_of :name
+ attr_accessor :raw_candidates
+ attr_accessor :reviewed
+
+ def validate
+ if @raw_candidates.length < 2
+ errors.add("You must list at least two candidates.")
+ end
+
+ if name =~ /[^A-Za-z0-9]/
+ errors.add("The name must only include numbers and letters.")
+ end
+ end
+
+ def initialize(params={})
+ super
+ self.enddate = DateTime.now + 30
+ self.active = 1
+ self.anonymous = 1
+ end
+
+ def candidatelist=(candstring='')
+ @raw_candidates = candstring.split(';').collect {|cand| cand.strip }
+ end
+
+ def candidatelist
+ @raw_candidates.join("; ")
+ end
+
+ def name
+ read_attribute( :name ).downcase()
+ end
+
+ def reviewed?
+ if reviewed.to_i == 1
+ return true
+ else
+ false
+ end
+ end
+
+ def create_candidates
+ @raw_candidates.each do |name|
+ candidate = Candidate.new({:name => name})
+ candidate.save
+ self.candidates << candidate
+ end
+ end
+end
<% %>
<html>
<head>
- <title><%= @page_title || "VotingBooth" %></title>
+ <title><%= @page_title || "HyperChad" %></title>
<%= stylesheet_link_tag "vb", :media => "all" %>
<% #engine_stylesheet 'login_engine' %>
<% if @page_title %>
<h3><%= @page_title %></h3>
<% else %>
- <h3>Voting Booth<br />
- <font size="-1">Preferential Voting on the Web</font></h3>
+ <h3>HyperChad<br />
+ <font size="-1">Voting Machinery for the Masses</font></h3>
<% end %>
<div id="links">
</div>
<hr />
- <div id="footer">(C) 2006 |
+ <div id="footer">Copyleft 2006 |
<%= link_to "MIT Media Lab", "http://www.media.mit.edu" %> and
<a href="http://mako.cc">Benjamin Mako Hill</a>
</div>
--- /dev/null
+<% -%>
+<h1>Create QuickVote</h1>
+
+<%= error_messages_for 'quickvote' %>
+
+<% if @quickvote %>
+<p>Please review the data you've entered and confirm. The candidates for
+the election submitted include:</p>
+
+<ul>
+<% for candidate in @quickvote.raw_candidates %>
+ <li><%= candidate %></li>
+<% end %>
+</ul>
+
+<% end %>
+
+<%= form_tag :action => 'create_quickvote' %>
+<!--[form:election]-->
+
+<p><label for="quickvote_name">Vote Name<br />
+
+<em><font size="-1">Required; 5-12 characters; only letters and numbers; no spaces</font></em></label><br/>
+
+<%= text_field 'quickvote', 'name' %></p>
+
+<p><label for="quickvote_description">Description <em><font
+size="-1">Optional</font></em></label><br/>
+
+<%= text_area 'quickvote', 'description', :rows => 2 %></p>
+
+<p><label for="quickvote_candidatelist">Choices/Candidates<em><br />
+<font size="-1">Seperate choices with a ";". At least two are required.</font></em></label><br/>
+
+<%= text_area 'quickvote', 'candidatelist', :rows => 3 %></p>
+
+<p><% if @quickvote -%>
+ <%= submit_tag "Confirm" -%>
+ <%= hidden_field :quickvote, :reviewed, :value => 1 %>
+ <% else %>
+ <%= submit_tag "Create QuickVote" -%>
+ <%- end -%>
+</p>
+
+<%= end_form_tag %>
+
<table width="auto" padding="5px">
<tr>
<td width="47%" valign="top">
+
+<h2>QuickVotes</h2>
+
+<p><em>QuickVotes</em> are unstructured votes, more like polls, without
+the voter verifiability, anonymity, and other more complex features of
+HyperChad. They are the quickest way to make a decision using a variety
+of preferential and non-preficial election methods, or to compare
+between methods.</p>
+
+<p><%= link_to "Create QuickVote.", :action => 'create_quickvote' %></p>
+
<h2>Voters</h2>
<p>If you have received an email with a token inviting you to vote in an
--- /dev/null
+<% %>
+
+<p>Vote Created</p>
+
+<p>You have successfully created a QuickVote.</p>
+
+<p>QuickVotes are open to the public but are not publicly listed on the
+HyperChad site. Voters do not need to log in or authenticate to
+participate in this election.</p>
+
+<p>Direct voters to:</p>
+<blockquote><strong><%= url_for :action => 'quickvote', :id => @quickvote.id, :only_path => false %></strong></blockquote>
+
+<p>This vote will expire on <em><%= @quickvote.enddate %></em></p>
+
--- /dev/null
+class CreateQuickVotes < ActiveRecord::Migration
+ def self.up
+ create_table :quick_votes do |t|
+ # t.column :name, :string
+ end
+ end
+
+ def self.down
+ drop_table :quick_votes
+ end
+end
--- /dev/null
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+first:
+ id: 1
+another:
+ id: 2
--- /dev/null
+require File.dirname(__FILE__) + '/../test_helper'
+
+class QuickVoteTest < Test::Unit::TestCase
+ fixtures :quick_votes
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end