added links to show for candidates

parent 3df41415
...@@ -6,4 +6,18 @@ class CandidatesController < ApplicationController ...@@ -6,4 +6,18 @@ class CandidatesController < ApplicationController
render "candidates/index.html.erb" render "candidates/index.html.erb"
end 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 end
\ No newline at end of file
...@@ -9,10 +9,23 @@ class VotesController < ApplicationController ...@@ -9,10 +9,23 @@ class VotesController < ApplicationController
redirect_to root_path, alert: "You have already voted." redirect_to root_path, alert: "You have already voted."
else else
@user = current_user.votes.build @user = current_user.votes.build
@vote = Vote.new
@positions = Position.all @positions = Position.all
end end
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 def checkout
if current_user.update(vote_params) if current_user.update(vote_params)
redirect_to root_path redirect_to root_path
......
...@@ -6,7 +6,10 @@ ...@@ -6,7 +6,10 @@
<th>Full Name</th> <th>Full Name</th>
</tr> </tr>
<% p.candidates.each do |candidate| %> <% p.candidates.each do |candidate| %>
<tr>
<td><%= candidate.first_name %> <%= candidate.last_name %></td> <td><%= candidate.first_name %> <%= candidate.last_name %></td>
<td><%= link_to "Show", candidate_path(candidate.id) %></td>
</tr>
<% end %> <% end %>
</table> </table>
<% end %> <% end %>
...@@ -16,4 +16,4 @@ ...@@ -16,4 +16,4 @@
</li> </li>
<% end %> <% end %>
</ul> </ul>
<%= link_to "Back to Candidates", admin_candidates_path %> <%= link_to "Back to Candidates", candidates_path %>
\ No newline at end of file \ No newline at end of file
...@@ -24,8 +24,10 @@ ...@@ -24,8 +24,10 @@
<th>Number of Votes</th> <th>Number of Votes</th>
</tr> </tr>
<% p.candidates.each do |candidate| %> <% 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> <td><%= Vote.where(candidate_id: candidate.id).count %></td>
</tr>
<% end %> <% end %>
</table> </table>
<% end %> <% end %>
......
<h1>Vote for your candidates.</h1> <h1>Vote for your candidates.</h1>
<%= simple_form_for(@user, url: checkout_path, method: :post) do |v| %> <%= simple_form_for @vote 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">
<br><br><br> <%= v.association :candidate, include_blank: false, collection: @candidates %>
</div>
</div>
<%= f.input :comments %>
<% end -%>
<% end -%>
<%= v.input :comments %><br>
<%= v.button :submit, "Vote", class: "btn btn-primary" %> <%= v.button :submit, "Submit" %>
<%= link_to "Back to Homepage", root_path, class: "btn btn-default" %>
<%= link_to "Vote Record", votes_index_path %>
<% end %> <% 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