<link rel"stylesheet" type="text/css" href="application.css">

<h1>Ballot</h1>

<% @candidates.each do |position_id, candidates| %>
<%= simple_form_for(@vote, url: confirm_vote_path, method: :post) do |o| %>
		
			<%= Position.find(position_id).name %>
				<ul> 
					<li><%= o.association :candidate, :collection => candidates %></li>
					<li><%= o.input :comments %></li>
				</ul>
				
				<% voted = false %>
				<% Vote.where(user_id: current_user.id).each do |v| %>
					<% if Candidate.find(v.candidate_id).position_id == position_id %>
						<% voted = true %>
					<% end %>
				<% end %>
				<% if voted == false %>
					<%= o.button :submit, "Vote" %>
					<h4><%= link_to "Back to Home", candidates_list_path %></h4>
				<% else %>
					<%= link_to "You have voted already", vote_path, disabled: true %>
					<h4><%= link_to "Back to Home", candidates_list_path %></h4>
				<% end %>
		<% end %>					
<% end %>

