added links to show for candidates

parent 3df41415
......@@ -6,4 +6,18 @@ class CandidatesController < ApplicationController
render "candidates/index.html.erb"
end
def show
@candidate = Candidate.find(params[:id])
@party_list = PartyList.where(candidate_id: (@candidate.id))
@votes = Vote.where(candidate_id: (@candidate.id))
@votes_male = Array.new
@votes_female = Array.new
@votes.each do |vote|
if vote.user.gender == "Male"
@votes_male.push(vote)
else
@votes_female.push(vote)
end
end
end
end
\ No newline at end of file
......@@ -9,10 +9,23 @@ class VotesController < ApplicationController
redirect_to root_path, alert: "You have already voted."
else
@user = current_user.votes.build
@vote = Vote.new
@positions = Position.all
end
end
def create
@candidate = Candidate.find(vote_params[:candidate_id])
@vote = Vote.new(vote_params)
@vote.user = current_user
if @vote.save
redirect_to root_path
else
render :action =>'new'
end
end
def checkout
if current_user.update(vote_params)
redirect_to root_path
......
......@@ -6,7 +6,10 @@
<th>Full Name</th>
</tr>
<% p.candidates.each do |candidate| %>
<tr>
<td><%= candidate.first_name %> <%= candidate.last_name %></td>
<td><%= link_to "Show", candidate_path(candidate.id) %></td>
</tr>
<% end %>
</table>
<% end %>
......@@ -16,4 +16,4 @@
</li>
<% end %>
</ul>
<%= link_to "Back to Candidates", admin_candidates_path %>
\ No newline at end of file
<%= link_to "Back to Candidates", candidates_path %>
\ No newline at end of file
......@@ -24,8 +24,10 @@
<th>Number of Votes</th>
</tr>
<% p.candidates.each do |candidate| %>
<td><%= candidate.first_name %> <%= candidate.last_name %></td>
<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>
<% end %>
......
<h1>Vote for your candidates.</h1>
<%= simple_form_for(@user, url: checkout_path, method: :post) do |v| %>
<% @positions.each do |p| %>
<%= v.simple_fields_for :votes do |f| %>
<h2><%= p.name %></h2>
<div class="row">
<div class="col-md-6">
<%= f.association :candidate, :collection => Candidate.where(position_id: (p.id)), include_blank: false, :label_method => lambda {|candidate| "#{candidate.last_name}, #{candidate.first_name}"}, as: :radio_buttons , label: "Candidates: "%>
<% Candidate.where(position_id: (p.id)).each do |candidate| %>
<p><div class="btn btn-primary btn-xs" data-toggle="popover" data-content="<%= candidate.slogan %>" style="margin-top: 2px; margin-bottom: 1px", data-trigger="focus", role="button", tabindex="0", title="<%= candidate.first_name %> <%= candidate.last_name %>"> View <%= candidate.last_name %>'s Slogan</div></p>
<% end -%>
</div>
<div class="col-md-6">
<%= simple_form_for @vote do |v| %>
<br><br><br>
</div>
</div>
<%= f.input :comments %>
<% end -%>
<% end -%>
<%= v.association :candidate, include_blank: false, collection: @candidates %>
<%= v.input :comments %><br>
<%= v.button :submit, "Vote", class: "btn btn-primary" %>
<%= link_to "Back to Homepage", root_path, class: "btn btn-default" %>
<%= link_to "Vote Record", votes_index_path %>
<%= v.button :submit, "Submit" %>
<% end %>
<script>
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
});
</script>
\ 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