Commit fff69c85 authored by Jego Reyes's avatar Jego Reyes

ayos

parent 042519a4
module Admin module Admin
class PositionsController < ApplicationController class PositionsController < ApplicationController
def show def index
@position = Position.find(params[:id]) @positions = Position.all
@candidates = @position.candidates render "admin/positions/index.html.erb"
render "admin/positions/show.html.erb" end
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
end end
\ No newline at end of file
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
<h2 style="margin-left:50px";> <h2 style="margin-left:50px";>
Candidates Candidates
</h2> </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> <hr>
......
...@@ -15,4 +15,4 @@ ...@@ -15,4 +15,4 @@
</h3> </h3>
<hr> <hr>
<%= link_to "Back to Candidates", admin_candidates_path %> <%= link_to "Back", admin_candidates_path %>
\ No newline at end of file \ 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> <link rel"stylesheet" type="text/css" href="application.css">
<h2>Candidates:</h2>
<ul>
<% @candidates.each do |c| %> <h1>
<li><%= link_to c.last_name candidate_path(c.id) %></li> <%= @position.name %>
<% end %> </h1>
</ul>
\ No newline at end of file
<hr>
<%= link_to "Back", admin_positions_path %>
\ No newline at end of file
...@@ -6,6 +6,7 @@ Rails.application.routes.draw do ...@@ -6,6 +6,7 @@ Rails.application.routes.draw do
get "/about", to: "pages#about" get "/about", to: "pages#about"
get "/index", to: "pages#index" get "/index", to: "pages#index"
resources :candidates resources :candidates
get "/positions/:id", to: "positions#show" get "/positions/:id", to: "positions#show"
get 'candidates_list', to: 'votes#index', as: :candidates_list get 'candidates_list', to: 'votes#index', as: :candidates_list
...@@ -15,6 +16,7 @@ Rails.application.routes.draw do ...@@ -15,6 +16,7 @@ Rails.application.routes.draw do
namespace :admin do namespace :admin do
resources :candidates resources :candidates
resources :positions
get "/positions/:id", to: "positions#show" get "/positions/:id", to: "positions#show"
end end
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