Commit 4b166785 authored by Bianca Tarun's avatar Bianca Tarun

edited show html

parent 79f3688f
class CandidatesController < ApplicationController
before_action :authenticate_user!
def index
@positions = Position.all
render "candidates/index.html.erb"
end
def show
@candidate = Candidate.find(params[:id])
@party_list = PartyList.where(candidate_id: (@candidate.id))
@votes = Vote.where(candidate_id: (@candidate.id))
@votes_male = Array.new
@votes_female = Array.new
@votes.each do |vote|
if vote.user.gender == "Male"
@votes_male.push(vote)
else
@votes_female.push(vote)
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
\ No newline at end of file
class ElectionController < ApplicationController
def vote
if Vote.exists?(candidate_id: params[:id], user_id: current_user.id)
render "candidates/show.html.erb"
else
redirect_to new_vote_path
end
end
end
\ No newline at end of file
<% if current_user.email == "admin_email@yahoo.com" %>
<h2>Candidate: <%= @candidate.first_name %> <%= @candidate.last_name %> </h2>
<% if !@candidate.party_list == nil %>
<h4>Party List: <%= @candidate.party_list.name %></h4>
<% else %>
<h4><%= "Independent Candidate" %></h4>
<% end %>
<h3><%= @candidate.last_name %>'s Slogan: <%= @candidate.slogan %></h3>
......
<h1>List of Candidates</h1>
<% @positions.each do |p| %>
<h2><%= p.name %></h2>
<table class="table table-hover", width="100%">
<tr>
<th>Full Name</th>
<th>Actions</th>
</tr>
<% p.candidates.each do |candidate| %>
<tr>
<td><%= candidate.first_name %> <%= candidate.last_name %></td>
<td><%= link_to "Show", candidate_path(candidate.id) %></td>
</tr>
<% end %>
</table>
<% end %>
<h2>Candidate: <%= @candidate.first_name %> <%= @candidate.last_name %> </h2>
<h4>Party List: <%= @candidate.party_list.name %></h4>
<h3><%= @candidate.last_name %>'s Slogan: <%= @candidate.slogan %></h3>
<ul>
<li>Votes: <%= @votes_male.size + @votes_female.size %></li>
<li>Male Voters: <%= @votes_male.size %> (<%= @percent_male %>%)</li>
<li>Female Voters: <%= @votes_female.size %> (<%= @percent_female %>%)</li>
</ul>
<h2>People who voted for <%= @candidate.first_name %> <%= @candidate.last_name %>:</h2>
<ul>
<li>User - Comment</li>
<% @votes.each do |v| %>
<li>
<%= v.user.email %> - <%= v.comments %>
</li>
<% end %>
</ul>
<%= link_to "Back to Candidates", candidates_path %>
......@@ -26,14 +26,13 @@
</tr>
<% p.candidates.each do |candidate| %>
<tr>
<td><%= link_to "#{candidate.first_name} #{candidate.last_name}", candidate_path(candidate.id) %></td>
<td><%="#{candidate.first_name} #{candidate.last_name}" %></td>
<td><%= Vote.where(candidate_id: candidate.id).count %></td>
</tr>
<% end %>
</table>
<% end %>
<hr>
<button type="button" class="btn btn-default"><%= link_to "View all Candidates", candidates_path %></button>
<button type="button" class="btn btn-default"><%= link_to "View all Party Lists", party_lists_index_path %></button>
<% else %>
<h4>You are not signed in. Please <%= link_to "Login", new_user_session_path %> or <%= link_to "Sign Up", new_user_registration_path %> to proceed with voting.</h4>
......
<h1>Positions</h1>
<hr>
<%= link_to("New Position", new_admin_position_path) %>
<hr>
<table width="100%", class="table table-hover">
<tr>
<th>Name</th>
</tr>
<% @positions.each do |position| %>
<tr>
<td><%= position.name %></td>
<td>
<%= link_to "Show", admin_position_path(position.id) %>
</td>
</tr>
<% end %>
</table>
<hr>
<%= link_to "Back to Homepage", root_path %>
\ No newline at end of file
<h1>Position: <%= @position.name %></h1>
<h2>Candidates:</h2>
<ul>
<% @candidates.each do |c| %>
<li><%= link_to c.nickname, candidate_path(c.id) %></li>
<% end %>
</ul>
\ No newline at end of file
......@@ -6,8 +6,6 @@ Rails.application.routes.draw do
resources :candidates
resources :party_lists
end
resources :candidates
resources :positions
root to: "pages#index"
......@@ -18,4 +16,5 @@ Rails.application.routes.draw do
get'/votes/index', to: "votes#index"
post'/checkout', to: 'votes#checkout', as: :checkout
end
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