Commit 44dbc0dc authored by April Guian's avatar April Guian

May nadagdag na di dapat

parent 25ece4ec
def vote
voted_for = false
@position = Position.find(params[:position_id])
#@candidate = params[:candidate_id]
#@pos = params[:id]
#@candidate = Candidate.new
#if current_user voted_for candidate.position
#Position.find(@position).candidates.each do |c|
# c.votes.each do |v|
# if current_user.id == v.user_id
# voted_for = true
# end
# end
#end
position.candidates.each do |c|
c.votes.each do |v|
if current_user.id == v.user_id
voted_for = true
end
end
end
#@post = Post.find(params[:post_id])
#@post.liked_by current_user
#respond_to do |format|
# format.html {redirect_to :back }
#end
#@position.voted_for current_user
if position.voted_for == false
# @vote = Vote.new
redirect_to new_voting_vote_path(@vote.id)
else
redirect_to admin_candidates_path
end
end
if position.voted_for == false
redirect_to new_voting_vote_path(@vote.id)
else
redirect_to admin_candidates_path, notice: "Sorry, you can only vote on a position and candidate once."
end
---------------
votes = Vote.all
voted_for = false
positions = Position.all
candidates = Candidate.all
@position = Position.find(params[:id])
candidates(@position).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
#@votes= Vote.all
@candidate = Candidate.find(params[:id])
#@vote = Vote.new
redirect_to new_voting_vote_path(@candidate)
else
redirect_to admin_candidates_path
end
\ 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