modified candidates controller and show

parent 6c976fe2
...@@ -45,6 +45,13 @@ class CandidatesController < ApplicationController ...@@ -45,6 +45,13 @@ class CandidatesController < ApplicationController
@votes_female.push(vote) @votes_female.push(vote)
end end
end end
if @votes.size == 0
@percent_male = 0
@percent_female = 0
else
@percent_male = @votes_male.size*100/@votes.size
@percent_female = @votes_female.size*100/@votes.size
end
end end
def destroy def destroy
@candidate = Candidate.find(params[:id]) @candidate = Candidate.find(params[:id])
......
...@@ -20,4 +20,11 @@ class CandidatesController < ApplicationController ...@@ -20,4 +20,11 @@ class CandidatesController < ApplicationController
end end
end end
end end
if @votes.size == 0
@percent_male = 0
@percent_female = 0
else
@percent_male = @votes_male.size*100/@votes.size
@percent_female = @votes_female.size*100/@votes.size
end
end end
\ No newline at end of file
...@@ -2,10 +2,12 @@ ...@@ -2,10 +2,12 @@
<h2>Candidate: <%= @candidate.first_name %> <%= @candidate.last_name %> </h2> <h2>Candidate: <%= @candidate.first_name %> <%= @candidate.last_name %> </h2>
<h4>Party List: <%= @candidate.party_list.name %></h4> <h4>Party List: <%= @candidate.party_list.name %></h4>
<h3><%= @candidate.last_name %>'s Slogan: <%= @candidate.slogan %></h3> <h3><%= @candidate.last_name %>'s Slogan: <%= @candidate.slogan %></h3>
<ul> <ul>
<li>Votes: <%= @votes_male.size + @votes_female.size %></li> <li>Votes: <%= @votes_male.size + @votes_female.size %></li>
<li>Male Voters: <%= @votes_male.size %> (<%= @votes_male.size*100/@votes.size %>%)</li> <li>Male Voters: <%= @votes_male.size %> (<%= @percent_male %>%)</li>
<li>Female Voters: <%= @votes_female.size %> (<%= @votes_female.size*100/@votes.size %>%)</li> <li>Female Voters: <%= @votes_female.size %> (<%= @percent_female %>%)</li>
</ul> </ul>
<% else %> <% else %>
<h1><%= "You do not have acces to this feature" %></h1> <h1><%= "You do not have acces to this feature" %></h1>
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
<h3><%= @candidate.last_name %>'s Slogan: <%= @candidate.slogan %></h3> <h3><%= @candidate.last_name %>'s Slogan: <%= @candidate.slogan %></h3>
<ul> <ul>
<li>Votes: <%= @votes_male.size + @votes_female.size %></li> <li>Votes: <%= @votes_male.size + @votes_female.size %></li>
<li>Male Voters: <%= @votes_male.size %> (<%= @votes_male.size*100/@votes.size %>%)</li> <li>Male Voters: <%= @votes_male.size %> (<%= @percent_male %>%)</li>
<li>Female Voters: <%= @votes_female.size %> (<%= @votes_female.size*100/@votes.size %>%)</li> <li>Female Voters: <%= @votes_female.size %> (<%= @percent_female %>%)</li>
</ul> </ul>
<h2>People who voted for <%= @candidate.first_name %> <%= @candidate.last_name %>:</h2> <h2>People who voted for <%= @candidate.first_name %> <%= @candidate.last_name %>:</h2>
...@@ -17,3 +17,4 @@ ...@@ -17,3 +17,4 @@
<% end %> <% end %>
</ul> </ul>
<%= link_to "Back to Candidates", candidates_path %> <%= link_to "Back to Candidates", candidates_path %>
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