Commit 6c976fe2 authored by Bianca Tarun's avatar Bianca Tarun

fixed admin views and added seeds

parent b748ee06
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
......@@ -2,6 +2,7 @@ class Vote < ActiveRecord::Base
belongs_to :user
belongs_to :candidate
validates :candidate_id, presence: true
validates :comments, presence: true
def to_s
"#{candidate.first_name} #{candidate.last_name}"
end
......
<% if current_user.email == "admin_email@yahoo.com" %>
<%= simple_form_for([:admin, @candidate]) do |f| %>
<%= f.input :first_name %>
<%= f.input :last_name %>
......@@ -6,4 +7,7 @@
<%= f.association :position, as: :select, include_blank: true, required: true %>
<%= f.input :slogan %>
<%= f.submit %>
<% end %>
<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
\ No newline at end of file
<% if current_user.email == "admin_email@yahoo.com" %>
<h1>Admin Edit Candidate</h1>
<%= render partial: "form" %>
<%= link_to "Back to Candidates", admin_candidates_path %>
<<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
\ No newline at end of file
<% if current_user.email == "admin_email@yahoo.com" %>
<h1>Admin Candidates</h1>
<hr>
<button type="button" class="btn btn-default"><%= link_to("New Candidate", new_admin_candidate_path) %></button>
......@@ -11,5 +12,7 @@
<% end %>
</ul>
<% end %>
<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
<% if current_user.email == "admin_email@yahoo.com" %>
<h1>Admin New Candidate</h1>
<%= render partial: "form" %>
<%= link_to "Back to Candidates", admin_candidates_path %>
<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
\ No newline at end of file
<% if current_user.email == "admin_email@yahoo.com" %>
<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>
......@@ -6,4 +7,6 @@
<li>Male Voters: <%= @votes_male.size %> (<%= @votes_male.size*100/@votes.size %>%)</li>
<li>Female Voters: <%= @votes_female.size %> (<%= @votes_female.size*100/@votes.size %>%)</li>
</ul>
<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
\ No newline at end of file
<% if current_user.email == "admin_email@yahoo.com" %>
<%= simple_form_for([:admin, @party_list]) do |f| %>
<%= f.input :name %>
<%= f.input :description %>
<%= f.submit %>
<% end %>
<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
\ No newline at end of file
<% if current_user.email == "admin_email@yahoo.com" %>
<h1>Admin Edit Party List</h1>
<%= render partial: "form" %>
<%= link_to "Back to Party Lists", admin_party_lists_path %>
\ No newline at end of file
<%= link_to "Back to Party Lists", admin_party_lists_path %>
<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
\ No newline at end of file
<% if current_user.email == "admin_email@yahoo.com" %>
<h1>Admin Party Lists</h1>
<hr>
<button type="button" class="btn btn-default"><%= link_to("New Party List", new_admin_party_list_path) %></button>
......@@ -7,7 +8,7 @@
<ul><h4>Candidates</h4></ul>
<ul><% p.candidates.each do |candidate| %>
<h5><%= candidate.first_name %> <%= candidate.last_name %> - <%= candidate.position.name %></h5>
<% end %>
</ul>
<h5>Actions: <%= link_to "Show", admin_party_list_path(p.id) %> <%= link_to "Edit", edit_admin_party_list_path(p.id) %> <%= link_to "Delete", admin_party_list_path(p.id), method: :delete, data: { confirm: 'Are you sure?' } %>
......@@ -15,4 +16,7 @@
<hr>
<% end %>
<hr>
<% else %>
<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
<% if current_user.email == "admin_email@yahoo.com" %>
<h1>Admin New Party List</h1>
<%= render partial: "form" %>
<%= link_to "Back to Party Lists", admin_party_lists_path %>
\ No newline at end of file
<%= link_to "Back to Party Lists", admin_party_lists_path %>
<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
\ No newline at end of file
<% if current_user.email == "admin_email@yahoo.com" %>
<h1>Party List: <%= @party_list.name %></h1>
<hr>
<h3>Party List Description </h3>
......@@ -6,4 +7,7 @@
<ul>Name: <%= candidate.first_name %> <%= candidate.last_name %> </ul>
<% end %>
<hr>
<%= link_to "Back to Party Lists", admin_party_lists_path %>
\ No newline at end of file
<%= link_to "Back to Party Lists", admin_party_lists_path %>
<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
\ No newline at end of file
<% if current_user.email == "admin_email@yahoo.com" %>
<%= simple_form_for([:admin, @position]) do |f| %>
<%= f.input :name %>
<%= f.submit %>
<% end %>
<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
\ No newline at end of file
<% if current_user.email == "admin_email@yahoo.com" %>
<h1>Admin Edit Position</h1>
<%= render partial: "form" %>
<%= link_to "Back to Position", admin_positions_path %>
\ No newline at end of file
<%= link_to "Back to Position", admin_positions_path %>
<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
\ No newline at end of file
<% if current_user.email == "admin_email@yahoo.com" %>
<h1>Admin Positions</h1>
<hr>
<button type="button" class="btn btn-default"><%= link_to("New Position", new_admin_position_path) %></button>
......@@ -18,3 +19,6 @@
<% end %>
</table>
<hr>
<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
\ No newline at end of file
<% if current_user.email == "admin_email@yahoo.com" %>
<h1>Admin New Position</h1>
<%= render partial: "form" %>
<%= link_to "Back to Position", admin_positions_path %>
<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
\ No newline at end of file
<% if current_user.email == "admin_email@yahoo.com" %>
<h1>Position: <%= @position.name %></h1>
<h2>Candidates:</h2>
<ul>
......@@ -5,4 +6,7 @@
<li><%= link_to "#{c.first_name}"+" #{c.last_name}", admin_candidate_path(c.id) %></li>
<% end %>
</ul>
<%= link_to "Back to Positions", admin_positions_path %>
\ No newline at end of file
<%= link_to "Back to Positions", admin_positions_path %>
<% else %>
<h1><%= "You do not have acces to this feature" %></h1>
<% end %>
\ No newline at end of file
......@@ -22,15 +22,12 @@
<table class="table table-hover", width="100%">
<tr>
<th>Full Name</th>
<th>Number of Votes</th>
<th>Number of Votes</th>
</tr>
<% p.candidates.each do |candidate| %>
<tr>
<td><%= link_to "#{candidate.first_name} #{candidate.last_name}", candidate_path(candidate.id) %></td>
<td><%= Vote.where(candidate_id: candidate.id).count %></td>
</tr>
<% end %>
</table>
......
<h1>Votes</h1>
<table width="100%">
<tr>
<th>Vote ID</th>
<tr>
<th>Vote ID</th>
<th>Candidate</th>
<th>Position</th>
<th>Comments</th>
</tr>
</tr>
<% @votes.each do |vote| %>
<% @votes.each do |vote| %>
<tr>
<td><%= vote.id %></td>
<td>
......
<h1>Vote Record</h1>
<table class="table">
<thead>
<th>Candidate</th>
<th>Position</th>
<th>Comments</th>
</thead>
<tbody>
<% if !@votes.empty? %>
<% @positions.each do |positions| %>
<% current_user.votes.each do |blah| %>
<% @candidates.each do |candidates| %>
<% if candidates.position.name == positions.name %>
<tr>
<td><%= candidates.first_name %> <%= candidates.last_name %></td>
<td><%= candidates.position.name %></td>
<td><%= blah.comments %></td>
</tr>
<% end %>
<% end %>
<% end %>
<% end %>
<% else %>
<tr>
<td colspan="3"><em>No Votes Found</em></td>
</tr>
<% end %>
</tbody>
</table>
<hr>
<%= link_to "Vote", votes_path %>
<%= link_to "Back to Homepage", root_path %>
\ No newline at end of file
......@@ -6,3 +6,14 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
User.create(first_name: 'Admin', last_name: 'Admin', birthday: '1992-09-03', email: 'admin_email@yahoo.com', password: 'password', gender: 'Male')
Position.create(name: 'President', id: 1)
Position.create(name: 'Vice President', id: 2)
PartyList.create(name: 'Party List A', description: 'AAA', id: 1)
PartyList.create(name: 'Party List B', description: 'BBB', id: 2)
PartyList.create(name: 'Party List C', description: 'CCC', id: 3)
Candidate.create(first_name: 'Cand.',last_name: 'A1', nickname: 'CA1', position_id: 1, party_list_id: 1, slogan: 'A1 all the way!')
Candidate.create(first_name: 'Cand.',last_name: 'A2', nickname: 'CA2', position_id: 2, party_list_id: 1, slogan: 'A2 all the way!')
Candidate.create(first_name: 'Cand.',last_name: 'B1', nickname: 'CB1', position_id: 1, party_list_id: 2, slogan: 'B1 all the way!')
Candidate.create(first_name: 'Cand.',last_name: 'B2', nickname: 'CB2', position_id: 2, party_list_id: 2, slogan: 'B2 all the way!')
Candidate.create(first_name: 'Cand.',last_name: 'C1', nickname: 'CC1', position_id: 1, party_list_id: 3, slogan: 'C1 all the way!')
Candidate.create(first_name: 'Cand.',last_name: 'C2', nickname: 'CC2', position_id: 2, party_list_id: 3, slogan: 'C2 all the way!')
\ No newline at end of file
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