Commit fff69c85 authored by Jego Reyes's avatar Jego Reyes

ayos

parent 042519a4
module Admin
class PositionsController < ApplicationController
def show
@position = Position.find(params[:id])
@candidates = @position.candidates
render "admin/positions/show.html.erb"
end
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 edit
@positions = Position.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 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 show
@position = Position.find(params[:id])
render "admin/positions/show.html.erb"
end
def destroy
@position = Position.find(params[:id])
@position.destroy!
redirect_to admin_positions_path
end
def position_params
params.require(:position).permit!
end
end
end
\ No newline at end of file
......@@ -7,8 +7,8 @@
<h2 style="margin-left:50px";>
Candidates
</h2>
<h5> <%= link_to "Add Candidate", new_admin_candidate_path %>
<h5 style="margin-left:50px";> <%= link_to "Add Candidate", new_admin_candidate_path %>
<h5 style="margin-left:50px";> <%= link_to "Add Position", new_admin_position_path %>
<hr>
......
......@@ -15,4 +15,4 @@
</h3>
<hr>
<%= link_to "Back to Candidates", admin_candidates_path %>
\ No newline at end of file
<%= link_to "Back", admin_candidates_path %>
\ No newline at end of file
<link rel"stylesheet" type="text/css" href="application.css">
<%= simple_form_for([:admin, @position]) do |p| %>
<%= p.input :name %>
<%= p.submit %>
<% end %>
<link rel"stylesheet" type="text/css" href="application.css">
<h1>Edit Position/h1>
<%= render partial: "form" %>
<%= link_to "Back", admin_positions_path %>
<link rel"stylesheet" type="text/css" href="application.css">
<h1 style="font-family:'Droid Sans';margin-left:50px;margin-top:50px;">
Election 2016
</h1>
<h2 style="margin-left:50px";>
Positions
</h2>
<h5 style="margin-left:50px";> <%= link_to "Add Position", new_admin_position_path %>
<hr>
<table width="100%", align="center">
<tr>
<th>Position</th>
</tr>
<% @positions.each do |a| %>
<tr>
<td><%= a.name %></td>
<td> <%= link_to "Show", admin_position_path(a.id) %>
<%= link_to "Edit", edit_admin_position_path(a.id) %>
<%= link_to "Delete", admin_position_path(a.id), method: :delete, data: { confirm: 'Are you sure?' } %>
</td>
</tr>
<% end %>
</table>
<br>
<h4 style="margin:100px;"><%= link_to "Home", root_path %></h4>
<link rel"stylesheet" type="text/css" href="application.css">
<h1>New Position</h1>
<%= render partial: "form" %>
<%= link_to "Back", admin_positions_path %>
\ No newline at end of file
<h1>Position: <%= @position.name %></h1>
<h2>Candidates:</h2>
<ul>
<% @candidates.each do |c| %>
<li><%= link_to c.last_name candidate_path(c.id) %></li>
<% end %>
</ul>
\ No newline at end of file
<link rel"stylesheet" type="text/css" href="application.css">
<h1>
<%= @position.name %>
</h1>
<hr>
<%= link_to "Back", admin_positions_path %>
\ No newline at end of file
......@@ -6,6 +6,7 @@ Rails.application.routes.draw do
get "/about", to: "pages#about"
get "/index", to: "pages#index"
resources :candidates
get "/positions/:id", to: "positions#show"
get 'candidates_list', to: 'votes#index', as: :candidates_list
......@@ -15,6 +16,7 @@ Rails.application.routes.draw do
namespace :admin do
resources :candidates
resources :positions
get "/positions/:id", to: "positions#show"
end
end
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