Commit 6eaa926e authored by April Guian's avatar April Guian

a

parent 7d42009a
class ElectionController < ApplicationController
before_action :authenticate_user!
def vote
@positions = Position.all
@position = Position.find(params[:id])
@candidates = Candidate.all
@votes = Vote.all
voted_for = false
@position.candidates.each do |c|
c.votes.each do |v|
if current_user.id == v.user_id
voted_for = true
end
end
end
if voted_for == false
redirect_to new_voting_vote_path
else
redirect_to voting_votes_path
end
end
def vote_params
params.require(:vote).permit!
end
end
\ No newline at end of file
......@@ -26,7 +26,7 @@ module Voting
voted_for = false
@pos = params[:id]
Position.find(@pos).candidates.each do |c|
Position.find(@pos).candidates.each do |c|
c.votes.each do |v|
if current_user.id == v.user_id
voted_for = true
......
......@@ -23,6 +23,9 @@
<div class="btn btn-info" role ="button">
<%=link_to "Delete", admin_candidate_path(@candidate.id), method: :delete, data: {confirm: 'Are you sure?'}%>
</div>
<div class="btn btn-info" role ="button">
<%=link_to "Vote", election_vote_path(@candidate.id) %>
</div>
<h2><%= @candidate.position.name %></h2>
<br>
......
......@@ -5,6 +5,7 @@ Rails.application.routes.draw do
get "/profile", to: "users/users#index"
get "/voting/new/:id", to: "voting/votes#new"
get "/election/vote/:id", to: "election#vote", as: :election_vote
get "/about" => "pages#about", as: :about
get "/about/evilla", to: "about#evilla"
......
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