Commit 4ea169ae authored by Kristoff Sison's avatar Kristoff Sison

added voting based on candidate id

parents f07015a9 4a293966
...@@ -24,7 +24,11 @@ class VotesController < ApplicationController ...@@ -24,7 +24,11 @@ class VotesController < ApplicationController
end end
def profile def profile
@positions = Position.all
@candidates = Candidate.all
@user = current_user
@votes = current_user.votes @votes = current_user.votes
render "votes/user_profile.html.erb"
end end
private private
......
...@@ -5,5 +5,5 @@ class Vote < ActiveRecord::Base ...@@ -5,5 +5,5 @@ class Vote < ActiveRecord::Base
def to_s def to_s
"#{candidate.first_name} #{candidate.last_name}" "#{candidate.first_name} #{candidate.last_name}"
end end
accepts_nested_attributes_for :votes #accepts_nested_attributes_for :votes
end end
...@@ -7,5 +7,17 @@ ...@@ -7,5 +7,17 @@
<li>Female Voters: <%= @votes_female.size %></li> <li>Female Voters: <%= @votes_female.size %></li>
</ul> </ul>
<<<<<<< HEAD
<%= link_to "Votes for Candidate", "/election/vote/#{@candidate.id}" %> <%= link_to "Votes for Candidate", "/election/vote/#{@candidate.id}" %>
=======
<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.comment %>
</li>
<% end %>
</ul>
>>>>>>> 4a293966901c2565a4eea2574a3086d230d926fc
<%= link_to "Back to Candidates", admin_candidates_path %> <%= link_to "Back to Candidates", admin_candidates_path %>
\ No newline at end of file
<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 %></li>
<li>Female Voters: <%= @votes_female.size %></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.comment %>
</li>
<% end %>
</ul>
<%= link_to "Back to Candidates", admin_candidates_path %>
\ No newline at end of file
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
</tr> </tr>
<% p.candidates.each do |candidate| %> <% p.candidates.each do |candidate| %>
<td><%= candidate.first_name %> <%= candidate.last_name %></td> <td><%= candidate.first_name %> <%= candidate.last_name %></td>
<td><%= candidate.votes.count %></td> <td><%= Vote.where(candidate_id: candidate.id).count %></td>
<% end %> <% end %>
</table> </table>
<% end %> <% end %>
......
<h1>Profile Page</h1> <h1>Profile Page</h1>
<h2><%= @user.first_name %> <%= @user.last_name %></h2> <h2><%= current_user.id %> <%= current_user.first_name %> <%= current_user.last_name %></h2>
<hr> <hr>
<table class="table table-striped"> <h2>Positions</h2>
<thead> <% @positions.each do |p| %>
<th>Vote ID</th> <h3><%= p.name %></h3>
<th>Candidate Voted</th> <% p.candidates.each do |c| %>
<th>Voted on</th> <% c.votes.each do |v| %>
</thead> <% if v.user_id == current_user.id %>
<tbody> <%= v.candidate.first_name %> <%= v.candidate.last_name %> <%= v.comments %>
<% @votes.each do |v| %> <% else %>
<tr> <% end %>
<td><%= v.id %></td> <% end %>
<td><%= v.candidate.first_name %> "<%= v.candidate.nickname %>" <%= v.candidate.last_name %></td> <% end %>
<td><%= v.created_at %></td>
</tr>
<% end %> <% end %>
</tbody>
</table>
<hr> <hr>
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