Commit 26f76714 authored by Wills Gomez's avatar Wills Gomez

fixed profile for finals

parents 475f9ba1 9a919a4f
......@@ -32,6 +32,7 @@ module Admin
@candidate.votes.each do |v|
v.destroy!
end
@candidate.destroy!
redirect_to admin_candidates_path
end
......
module Admin
class UsersController < ApplicationController
before_action :authenticate_user!
def index
@positions = Position.all
@candidates = Candidate.all
@votes = Vote.all
@users = User.all
render "admin/users/index.html.erb"
end
def new
@user = User.new
render "admin/users/new.html.erb"
end
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
if @user.update(position_params())
redirect_to admin_users_path(@user.id)
else
render "admin/user/edit.html.erb"
end
end
def destroy
@candidate = User.find(params[:id])
@candidate.destroy!
redirect_to admin_users_path
end
def create
@user = User.new(position_params())
if @user.save
redirect_to admin_user_path(@user.id)
else
render "admin/users/new.html.erb"
end
end
def show
@positions = Position.all
@candidates = Candidate.all
@votes = Vote.all
@user = User.find(params[:id])
render "admin/users/show.html.erb"
end
def user_params
params.require(:user).permit!
end
end
end
\ No newline at end of file
......@@ -5,6 +5,7 @@ module Users
@positions = Position.all
@candidates = Candidate.all
@votes = Vote.all
@currentuser = current_user
render "pages/profile.html.erb"
end
end
......
<% provide(:title, "Users" ) %>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1>Users</h1>
<hr>
<% @users.each do |u| %>
<ul>
<li>
User ID: <%= u.id %>
</li>
<li>
Full Name: <%= u.full_name %>
</li>
<li>Candidates Voted:
<ul>
<% u.votes.each do |v|%>
<li>
<%= v.candidate.full_name %> - <%= v.candidate.position.name %>
</li>
<%end%>
</ul>
</li>
<li>
Actions:
<ul>
<% if current_user.id == u.id %>
<div class="btn btn-info" role ="button">
<%= link_to "Show Your Profile", admin_user_path(u.id) %>
</div>
<div class="btn btn-danger" role ="button">
<%= link_to "Cannot Delete Your Own!" %>
</div>
<% else %>
<div class="btn btn-info" role ="button">
<%= link_to "Show User's Profile", admin_user_path(u.id) %>
</div>
<div class="btn btn-info" role ="button">
<%= link_to "Delete User", admin_user_path(u.id), method: :delete, data: { confirm: 'Are you sure?' } %>
</div>
<%end%>
</ul>
</li>
</ul>
<hr>
<%end%>
</div>
</div>
</div>
<% provide(:title, "#{@user.full_name}" ) %>
<div class="container">
<div class="row">
<div class="col-md-12">
<% if @user.votes.size > 0 %>
<% @user.votes.each do |v|%>
<li>
<%="#{v.candidate.position.name}: #{v.candidate.full_name}"%>
<p>
Comments: <%=v.comment%>
</p>
</li>
<%end%>
<%else%>
<center>
<% if current_user.id == @user.id %>
<h4> <%= link_to "You haven't voted for any candidates yet. Vote Now!", "/voting/votes" %> </h4>
<%else%>
<h4> <%=user.full_name %> has not casted their votes yet %> </h4>
<%end%>
</center>
<%end%>
</div>
</div>
</div>
\ No newline at end of file
......@@ -29,6 +29,13 @@
</u1>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Admin Stuff<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><%= link_to "List of Users", admin_users_path %></li>
</u1>
</ul>
</li>
<%else%>
<li><%= link_to "Log-in", new_user_session_path %></li>
<li><%= link_to "Register", new_user_registration_path %></li>
......
......@@ -30,6 +30,8 @@
</table>
<hr>
<%end%>
<%= link_to "List of Users", admin_users_path %>
</div>
</div>
</div>
\ No newline at end of file
</div>
<% provide(:title, "#{@currentuser.full_name}" ) %>
<div class ="container">
<div class="row">
<div class="col-md-12">
<h2>Hey <%=current_user.first_name%>!</h2>
<br>
<<<<<<< HEAD
<h4>You Voted for:</h4>
<br>
<ul>
......@@ -34,6 +38,26 @@
<h5></h5>
<%end%>
</ul>
=======
<% if @currentuser.votes.size > 0 %>
You Voted for:
<br>
<ul>
<%current_user.votes.each do |v|%>
<li>
<%="#{v.candidate.position.name}: #{v.candidate.full_name}"%>
<p>
Comments: <%=v.comment%>
</p>
</li>
<%end%>
</ul>
<%else%>
<center>
<h4> <%= link_to "You haven't voted for any candidates yet. Vote Now!", "/voting/votes" %> </h4>
</center>
<%end%>
>>>>>>> 9a919a4f1954bbaa640bd8813e4bc205c39e1657
</div>
</div>
</div>
\ No newline at end of file
<td>
<%= link_to user.email, user %>
</td>
<td>
<%= form_for(user) do |f| %>
<%= f.select(:role, User.roles.keys.map {|role| [role.titleize,role]}) %>
<%= f.submit 'Change Role', :class => 'button-xs' %>
<% end %>
</td>
<td>
<%= link_to("Delete user", user_path(user), :data => { :confirm => "Are you sure?" }, :method => :delete, :class => 'button-xs') unless user == current_user %>
</td>
\ No newline at end of file
<div class="container">
<div class="row">
<h3>Users</h3>
<div class="column">
<table class="table">
<tbody>
<% @users.each do |user| %>
<tr>
<%= render user %>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
\ No newline at end of file
<h3>User</h3>
<p>Name: <%= @user.name if @user.name %></p>
<p>Email: <%= @user.email if @user.email %></p>
......@@ -24,7 +24,9 @@
<%end%>
<% end %>
<%if !voted_for%>
<%=link_to "Vote for a #{p.name}", "/voting/new/#{p.id}" %>
<div class="btn btn-info" role ="button">
<%=link_to "Vote for a #{p.name}", "/voting/new/#{p.id}" %>
</div>
<%else%>
<%end%>
<% else %>
......
......@@ -3,8 +3,6 @@ Rails.application.routes.draw do
devise_for :users
resources :users
get "/profile", to: "users/users#index"
get "/voting/new/:id", to: "voting/votes#new"
......@@ -23,5 +21,6 @@ Rails.application.routes.draw do
namespace :admin do
resources :candidates
resources :positions
resources :users
end
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