Commit a2dbb107 authored by royce-matthew's avatar royce-matthew

added defense items and progressbar

parent 4240cb07
...@@ -26,6 +26,10 @@ module Admin ...@@ -26,6 +26,10 @@ module Admin
end end
def destroy def destroy
@candidate = Candidate.find(params[:id]) @candidate = Candidate.find(params[:id])
@candidate.votes.each do |v|
v.destroy!
end
@candidate.destroy! @candidate.destroy!
redirect_to admin_candidates_path redirect_to admin_candidates_path
end end
......
...@@ -23,10 +23,27 @@ module Voting ...@@ -23,10 +23,27 @@ module Voting
end end
def new def new
@votes= Vote.all voted_for = false
@pos = params[:id] @pos = params[:id]
Position.find(@pos).candidates.each do |c|
c.votes.each do |v|
if current_user.id == v.user_id
voted_for = true
end
end
end
if voted_for == false
@votes= Vote.all
@vote = Vote.new @vote = Vote.new
render "voting/votes/new.html.erb" render "voting/votes/new.html.erb"
else
redirect_to voting_votes_path
end
end end
def create def create
......
...@@ -35,6 +35,8 @@ o=0 ...@@ -35,6 +35,8 @@ o=0
%> %>
<%end%> <%end%>
<div class="row"> <div class="row">
...@@ -52,3 +54,13 @@ o=0 ...@@ -52,3 +54,13 @@ o=0
</div> </div>
<hr> <hr>
<%= link_to "Back to Candidates", admin_candidates_path %> <%= link_to "Back to Candidates", admin_candidates_path %>
<%@candidate.votes.each do |v|%>
<li><%="#{v.user.email}:"%>
<p style="">Comments: <%=v.comments%>
</p>
</li>
<%end%>
\ No newline at end of file
...@@ -5,9 +5,15 @@ ...@@ -5,9 +5,15 @@
<h4><%=p.name%></h4> <h4><%=p.name%></h4>
<table style="width:300px;"> <table style="width:300px;">
<thead><td>Name</td><td>Slogan</td><td>Votes</td></thead> <thead><td>Name</td><td>Slogan</td><td>Votes</td></thead>
<%total = 0%>
<%p.candidates.each do |c|%>
<%total = total+c.votes.count%>
<%end%>
<%p.candidates.each do |c|%> <%p.candidates.each do |c|%>
<tr><td><%=link_to c.full_name, admin_candidate_path(c.id), {:style =>"font-size:15 px;"}%></td><td ><%=c.slogan%></td><td><%=c.votes.count%></td></tr> <tr><td><%=link_to c.full_name, admin_candidate_path(c.id), {:style =>"font-size:15 px;"}%></td><td ><%=c.slogan%></td><td><%=c.votes.count%></td>
<td> <progress value="<%=c.votes.count%>" max="<%=total%>" ></td>
</tr>
<%end%> <%end%>
</table> </table>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment