Commit 5fed7c3e authored by Galen Evilla's avatar Galen Evilla

added if else

parent 3a6e2d88
...@@ -2,6 +2,7 @@ module Admin ...@@ -2,6 +2,7 @@ module Admin
class CandidatesController < ApplicationController class CandidatesController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
def index def index
@candidates = Candidate.all
@positions = Position.all @positions = Position.all
render "admin/candidates/index.html.erb" render "admin/candidates/index.html.erb"
end end
......
...@@ -2,6 +2,7 @@ module Admin ...@@ -2,6 +2,7 @@ module Admin
class PositionsController < ApplicationController class PositionsController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
def index def index
@positions = Position.all @positions = Position.all
render "admin/positions/index.html.erb" render "admin/positions/index.html.erb"
end end
...@@ -42,6 +43,7 @@ module Admin ...@@ -42,6 +43,7 @@ module Admin
end end
def show def show
@candidates = Candidate.all
@position = Position.find(params[:id]) @position = Position.find(params[:id])
render "admin/positions/show.html.erb" render "admin/positions/show.html.erb"
end end
......
...@@ -11,28 +11,45 @@ ...@@ -11,28 +11,45 @@
<div class="col-md-12"> <div class="col-md-12">
<left> <left>
<h1>Candidates</h1> <h1>Candidates</h1>
<div class="btn btn-info" role ="button">
<%= link_to "Add a Candidate", new_admin_candidate_path, :method => "get" %>
</div>
</left> </left>
<% if @positions.size > 0 %> <% if @positions.size > 0 %>
<%@positions.each do |p|%> <%@positions.each do |p|%>
<hr> <hr>
<h3><center><%=p.name%></center></h3> <h3><center><%=p.name%></center></h3>
<table>
<%p.candidates.each do |c|%> <% if p.candidates.size > 0 %>
<tr> <table class="table table-hover">
<td> <thead>
<center> <th width ="40%"><center>Name</center></th>
<%=link_to c.full_name, admin_candidate_path(c.id)%> <th><center>Slogan</center></th>
</center> </thead>
</td>
</tr> <%p.candidates.each do |c|%>
<tr>
<td>
<center>
<%=link_to c.full_name, admin_candidate_path(c.id)%>
</center>
</td>
<td>
<center>
<%=c.slogan%>
</center>
</td>
</tr>
<%end%>
<%else%>
<h4><center>No created candidates.</center></h4>
<%end%> <%end%>
<center>
<div class="btn btn-info" role ="button">
<%= link_to "Add a Candidate", new_admin_candidate_path, :method => "get" %>
</div>
</center>
</table> </table>
<%end%> <%end%>
<% else %> <% else %>
<h4>No created candidates.</h4> <h4><center>No created candidates.</center></h4>
<% end %> <% end %>
</div> </div>
</div> </div>
......
...@@ -26,11 +26,20 @@ ...@@ -26,11 +26,20 @@
<hr> <hr>
<h2>Candidates for <%=@position.name%></h2> <h2>Candidates for <%=@position.name%></h2>
<ul> <% if @position.candidates.size > 0 %>
<%@position.candidates.each do |c|%> <ul>
<li><%=link_to c.full_name, admin_candidate_path(c.id)%></li> <%@position.candidates.each do |c|%>
<%end%> <li><%=link_to c.full_name, admin_candidate_path(c.id)%></li>
</ul> <%end%>
</ul>
<%else%>
<h4>No Candidates for <%= @position.name%> </h4>
<div class="btn btn-info" role ="button">
<%= link_to "Add a Candidate", new_admin_candidate_path, :method => "get" %>
</div>
<br>
<%end%>
<br> <br>
<%= link_to "Back to Positions", admin_positions_path %> <%= link_to "Back to Positions", admin_positions_path %>
......
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