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

edited user profile

parent bd423676
......@@ -24,7 +24,11 @@ class VotesController < ApplicationController
end
def profile
@positions = Position.all
@candidates = Candidate.all
@user = current_user
@votes = current_user.votes
render "votes/user_profile.html.erb"
end
private
......
......@@ -5,5 +5,5 @@ class Vote < ActiveRecord::Base
def to_s
"#{candidate.first_name} #{candidate.last_name}"
end
accepts_nested_attributes_for :votes
#accepts_nested_attributes_for :votes
end
......@@ -25,7 +25,7 @@
</tr>
<% p.candidates.each do |candidate| %>
<td><%= candidate.first_name %> <%= candidate.last_name %></td>
<td><%= candidate.votes.count %></td>
<td><%= Vote.where(candidate_id: candidate.id).count %></td>
<% end %>
</table>
<% end %>
......
<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>
<table class="table table-striped">
<thead>
<th>Vote ID</th>
<th>Candidate Voted</th>
<th>Voted on</th>
</thead>
<tbody>
<% @votes.each do |v| %>
<tr>
<td><%= v.id %></td>
<td><%= v.candidate.first_name %> "<%= v.candidate.nickname %>" <%= v.candidate.last_name %></td>
<td><%= v.created_at %></td>
</tr>
<h2>Positions</h2>
<% @positions.each do |p| %>
<h3><%= p.name %></h3>
<% p.candidates.each do |c| %>
<% c.votes.each do |v| %>
<% if v.user_id == current_user.id %>
<%= v.candidate.first_name %> <%= v.candidate.last_name %> <%= v.comments %>
<% else %>
<% end %>
<% end %>
</tbody>
</table>
<% end %>
<% end %>
<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