Commit 4f024caf authored by April Guian's avatar April Guian

Added Admin

parent 9b8dc62a
module Admin
class CandidatesController < ApplicationController
before_action :authenticate_user!
def index
@positions = Position.all
@candidates = Candidate.all
render "admin/candidates/index.html.erb"
end
def show
@candidate = Candidate.find(params[:id])
render "admin/candidates/show.html.erb"
end
def destroy
@candidate = Candidate.find(params[:id])
@candidate.destroy!
redirect_to admin_candidates_path
end
def new
@candidate = Candidate.new
render "admin/candidates/new.html.erb"
end
def create
@candidate = Candidate.new(candidate_params())
if @candidate.save
flash[:success] = 'Candidate was created!'
redirect_to admin_candidate_path(@candidate.id)
else
render "admin/candidates/new.html.erb"
end
end
def edit
@candidate = Candidate.find(params[:id])
end
def update
@candidate = Candidate.find(params[:id])
if @candidate.update(candidate_params())
redirect_to admin_candidate_path(@candidate.id)
else
render "admin/candidates/edit.html.erb"
end
end
def candidate_params
params.require(:candidate).permit!
end
end
end
\ No newline at end of file
module Admin
class PositionsController < ApplicationController
before_action :authenticate_user!
def index
@positions = Position.all
render "admin/positions/index.html.erb"
end
def show
@position = Position.find(params[:id])
@candidates = @position.candidates
render "admin/positions/show.html.erb"
end
def destroy
@position = Positions.find(params[:id])
@position.destroy!
redirect_to admin_positions_path
end
def new
@position = Position.new
render "admin/positions/new.html.erb"
end
def create
@position = Position.new(position_params())
if @position.save
redirect_to admin_position_path(@position.id)
else
render "admin/positions/new.html.erb"
end
end
def edit
@position = Positions.find(params[:id])
end
def update
@position = Positions.find(params[:id])
if @position.update(position_params())
redirect_to admin_position_path(@position.id)
else
render "admin_positions/edit.html.erb"
end
end
def position_params
params.require(:position).permit!
end
end
end
\ No newline at end of file
class CandidatesController < ApplicationController class CandidatesController < ApplicationController
before_action :authenticate_user!
def index def index
@positions = Position.all @positions = Position.all
@candidates = Candidate.all @candidates = Candidate.all
......
<%= simple_form_for([:admin, @candidate]) do |f| %>
<%= f.input :first_name, label: 'First Name: '%>
<%= f.input :last_name, label: 'Last Name: '%>
<%= f.input :slogan, label: 'Slogan: '%>
<%= f.association :position, label: 'Position: '%>
<%= f.submit %>
<% end %>
<h1>Edit Candidate</h1> <h1>Edit Candidate</h1>
<% if admin_signed_in? %> <% if user_signed_in? %>
Hello Admin! Hello Admin!
<%= render partial: "form" %> <%= render partial: "form" %>
<%= link_to "Back to List of Positions", admin_candidates_path %>
<% else %> <% else %>
You are not signed in. Please go to login page. You are not signed in. Please go to login page.
<% end %> <%= link_to Login, new_user_session_path %>
\ No newline at end of file
<% end %>
<%= link_to "Back to List of Candidates", admin_candidates_path %>
\ No newline at end of file
<h1>2016 Election Candidates</h1>
<%= link_to("New Candidate", new_admin_candidate_path) %>
<hr>
<table width="100%">
<tr>
<th>Name</th>
<th>Slogan</th>
<th>Position</th>
<th>Actions</th>
</tr>
<% @candidates.each do |c| %>
<tr align="center">
<td><%= c.first_name %> <%= c.last_name %></td>
<td><%= c.slogan %></td>
<td><%= c.position.name %></td>
<td>
<%= link_to "Show", admin_candidate_path(c.id) %>
<%= link_to "Edit", edit_admin_candidate_path(c.id) %>
<%= link_to "Delete", admin_candidate_path(c.id), method: :delete, data: { confirm: 'Are you sure?' } %>
</td>
</tr>
<% end %>
</table>
<hr>
<hr>
<%= link_to "Home", root_path %>
<br>
<%= link_to "View Positions", admin_positions_path %>
\ No newline at end of file
<h1>Edit Position</h1> <h1>Add New Candidate</h1>
<% if admin_signed_in? %> <% if user_signed_in? %>
Hello Admin! Hello Admin!
<%= render partial: "form" %> <%= render partial: "form" %>
<%= link_to "Back to List of Positions", admin_positions_path %>
<% else %> <% else %>
You are not signed in. Please go to login page. You are not signed in. Please go to login page.
<% end %> <%= link_to Login, new_user_session_path %>
\ No newline at end of file
<% end %>
<%= link_to "Back to List of Candidates", admin_candidates_path %>
\ No newline at end of file
<h1><%= @candidate.first_name %> <%= @candidate.last_name %></h1>
<h3>Position: <%= @candidate.position.name%> </h3>
<h3>Slogan:</h3>
<p>
<%= @candidate.slogan %>
</p>
<hr>
<%= link_to "Back to Candidates", admin_candidates_path %>
<h1>Edit Position</h1> <h1>Edit Position</h1>
<% if admin_signed_in? %> <% if user_signed_in? %>
Hello User! Hello User!
<%= render partial: "form" %> <%= render partial: "form" %>
<%= link_to "Back to List of Positions", admin_posts_path %>
<% else %> <% else %>
You are not signed in. Please go to login page. You are not signed in. Please go to login page.
<% end %> <%= link_to Login, new_user_session_path %>
\ No newline at end of file
<% end %>
<%= link_to "Back to List of Positions", admin_postitions_path %>
\ No newline at end of file
<h1>2016 Elections Positions</h1>
<% @positions.each do |c| %>
<h2>(<%= c.id %>) <%= c.name %></h2>
<ul>
<% c.candidates.each do |p| %>
<li><%= link_to "#{p.first_name} #{p.last_name}" , admin_candidate_path(p.id) %></li>
<% end %>
</ul>
<%= link_to "View all Candidates under #{c.name}" , "admin/positions/#{c.id}" %>
<% end %>
<%= link_to("Add New Position", new_admin_position_path) %>
<hr>
<%= link_to "View Candidates", admin_candidates_path %>
<br>
<%= link_to "Home", root_path %>
<h1>Edit Candidate</h1> <h1>Add New Position</h1>
<% if admin_signed_in? %> <% if user_signed_in? %>
Hello Admin! Hello User!
<%= render partial: "form" %> <%= render partial: "form" %>
<%= link_to "Back to List of Positions", admin_candidates_path %>
<% else %> <% else %>
You are not signed in. Please go to login page. You are not signed in. Please go to login page.
<% end %> <%= link_to Login, new_user_session_path %>
\ No newline at end of file
<% end %>
<%= link_to "Back to List of Positions", admin_positions_path %>
\ No newline at end of file
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
<h2>Candidates:</h2> <h2>Candidates:</h2>
<ul> <ul>
<% @candidates.each do |c| %> <% @candidates.each do |c| %>
<li><%= link_to c.last_name, admin_candidate_path(c.id) %></li> <li><%= link_to "#{p.first_name} #{p.last_name}", admin_candidate_path(p.id) %></li>
<% end %> <% end %>
</ul> </ul>
\ No newline at end of file
<hr>
<%= link_to "Back to List of Positions", admin_positions_path %>
\ No newline at end of file
<h1>Poller</h1> <h1>Poller</h1>
<%= link_to "Manage Positions Under Admin", admin_positions_path %>
<br>
<%= link_to "Manage Candidates Under Admin", admin_candidates_path %>
<br>
<%= link_to "View Positions", positions_path %> <%= link_to "View Positions", positions_path %>
<br> <br>
<%= link_to "View Candidates", candidates_path %> <%= link_to "View Candidates", candidates_path %>
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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