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 ...@@ -2,6 +2,7 @@ class Vote < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :candidate belongs_to :candidate
validates :candidate_id, presence: true validates :candidate_id, presence: true
validates :comments, presence: true
def to_s def to_s
"#{candidate.first_name} #{candidate.last_name}" "#{candidate.first_name} #{candidate.last_name}"
end end
......
<% if current_user.email == "admin_email@yahoo.com" %>
<%= simple_form_for([:admin, @candidate]) do |f| %> <%= simple_form_for([:admin, @candidate]) do |f| %>
<%= f.input :first_name %> <%= f.input :first_name %>
<%= f.input :last_name %> <%= f.input :last_name %>
...@@ -7,3 +8,6 @@ ...@@ -7,3 +8,6 @@
<%= f.input :slogan %> <%= f.input :slogan %>
<%= f.submit %> <%= f.submit %>
<% end %> <% 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> <h1>Admin Edit Candidate</h1>
<%= render partial: "form" %> <%= render partial: "form" %>
<%= link_to "Back to Candidates", admin_candidates_path %> <%= 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> <h1>Admin Candidates</h1>
<hr> <hr>
<button type="button" class="btn btn-default"><%= link_to("New Candidate", new_admin_candidate_path) %></button> <button type="button" class="btn btn-default"><%= link_to("New Candidate", new_admin_candidate_path) %></button>
...@@ -11,5 +12,7 @@ ...@@ -11,5 +12,7 @@
<% end %> <% end %>
</ul> </ul>
<% end %> <% 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> <h1>Admin New Candidate</h1>
<%= render partial: "form" %> <%= render partial: "form" %>
<%= link_to "Back to Candidates", admin_candidates_path %> <%= 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> <h2>Candidate: <%= @candidate.first_name %> <%= @candidate.last_name %> </h2>
<h4>Party List: <%= @candidate.party_list.name %></h4> <h4>Party List: <%= @candidate.party_list.name %></h4>
<h3><%= @candidate.last_name %>'s Slogan: <%= @candidate.slogan %></h3> <h3><%= @candidate.last_name %>'s Slogan: <%= @candidate.slogan %></h3>
...@@ -6,4 +7,6 @@ ...@@ -6,4 +7,6 @@
<li>Male Voters: <%= @votes_male.size %> (<%= @votes_male.size*100/@votes.size %>%)</li> <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> <li>Female Voters: <%= @votes_female.size %> (<%= @votes_female.size*100/@votes.size %>%)</li>
</ul> </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| %> <%= simple_form_for([:admin, @party_list]) do |f| %>
<%= f.input :name %> <%= f.input :name %>
<%= f.input :description %> <%= f.input :description %>
<%= f.submit %> <%= f.submit %>
<% end %> <% 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> <h1>Admin Edit Party List</h1>
<%= render partial: "form" %> <%= render partial: "form" %>
<%= link_to "Back to Party Lists", admin_party_lists_path %> <%= 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> <h1>Admin Party Lists</h1>
<hr> <hr>
<button type="button" class="btn btn-default"><%= link_to("New Party List", new_admin_party_list_path) %></button> <button type="button" class="btn btn-default"><%= link_to("New Party List", new_admin_party_list_path) %></button>
...@@ -15,4 +16,7 @@ ...@@ -15,4 +16,7 @@
<hr> <hr>
<% end %> <% end %>
<hr> <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> <h1>Admin New Party List</h1>
<%= render partial: "form" %> <%= render partial: "form" %>
<%= link_to "Back to Party Lists", admin_party_lists_path %> <%= 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> <h1>Party List: <%= @party_list.name %></h1>
<hr> <hr>
<h3>Party List Description </h3> <h3>Party List Description </h3>
...@@ -7,3 +8,6 @@ ...@@ -7,3 +8,6 @@
<% end %> <% end %>
<hr> <hr>
<%= link_to "Back to Party Lists", admin_party_lists_path %> <%= 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| %> <%= simple_form_for([:admin, @position]) do |f| %>
<%= f.input :name %> <%= f.input :name %>
<%= f.submit %> <%= f.submit %>
<% end %> <% 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> <h1>Admin Edit Position</h1>
<%= render partial: "form" %> <%= render partial: "form" %>
<%= link_to "Back to Position", admin_positions_path %> <%= 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> <h1>Admin Positions</h1>
<hr> <hr>
<button type="button" class="btn btn-default"><%= link_to("New Position", new_admin_position_path) %></button> <button type="button" class="btn btn-default"><%= link_to("New Position", new_admin_position_path) %></button>
...@@ -18,3 +19,6 @@ ...@@ -18,3 +19,6 @@
<% end %> <% end %>
</table> </table>
<hr> <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> <h1>Admin New Position</h1>
<%= render partial: "form" %> <%= render partial: "form" %>
<%= link_to "Back to Position", admin_positions_path %> <%= 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> <h1>Position: <%= @position.name %></h1>
<h2>Candidates:</h2> <h2>Candidates:</h2>
<ul> <ul>
...@@ -6,3 +7,6 @@ ...@@ -6,3 +7,6 @@
<% end %> <% end %>
</ul> </ul>
<%= link_to "Back to Positions", admin_positions_path %> <%= 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
...@@ -20,3 +20,4 @@ ...@@ -20,3 +20,4 @@
</body> </body>
</html> </html>
...@@ -23,14 +23,11 @@ ...@@ -23,14 +23,11 @@
<tr> <tr>
<th>Full Name</th> <th>Full Name</th>
<th>Number of Votes</th> <th>Number of Votes</th>
</tr> </tr>
<% p.candidates.each do |candidate| %> <% p.candidates.each do |candidate| %>
<tr> <tr>
<td><%= link_to "#{candidate.first_name} #{candidate.last_name}", candidate_path(candidate.id) %></td> <td><%= link_to "#{candidate.first_name} #{candidate.last_name}", candidate_path(candidate.id) %></td>
<td><%= Vote.where(candidate_id: candidate.id).count %></td> <td><%= Vote.where(candidate_id: candidate.id).count %></td>
</tr> </tr>
<% end %> <% end %>
</table> </table>
......
<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 @@ ...@@ -6,3 +6,14 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first) # 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') 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