Fixed add candidate, show, edit, delete; Initially fixed add position

parent 70646218
...@@ -38,6 +38,7 @@ GEM ...@@ -38,6 +38,7 @@ GEM
tzinfo (~> 1.1) tzinfo (~> 1.1)
arel (6.0.3) arel (6.0.3)
bcrypt (3.1.11) bcrypt (3.1.11)
bcrypt (3.1.11-x86-mingw32)
binding_of_caller (0.7.2) binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1) debug_inspector (>= 0.0.1)
builder (3.2.2) builder (3.2.2)
...@@ -83,6 +84,9 @@ GEM ...@@ -83,6 +84,9 @@ GEM
nokogiri (1.6.8) nokogiri (1.6.8)
mini_portile2 (~> 2.1.0) mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7) pkg-config (~> 1.1.7)
nokogiri (1.6.8-x86-mingw32)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
orm_adapter (0.5.0) orm_adapter (0.5.0)
pkg-config (1.1.7) pkg-config (1.1.7)
rack (1.6.4) rack (1.6.4)
...@@ -139,6 +143,7 @@ GEM ...@@ -139,6 +143,7 @@ GEM
activesupport (>= 4.0) activesupport (>= 4.0)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
sqlite3 (1.3.11) sqlite3 (1.3.11)
sqlite3 (1.3.11-x86-mingw32)
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.5) thread_safe (0.3.5)
tilt (2.0.5) tilt (2.0.5)
...@@ -147,6 +152,8 @@ GEM ...@@ -147,6 +152,8 @@ GEM
turbolinks-source (5.0.0) turbolinks-source (5.0.0)
tzinfo (1.2.2) tzinfo (1.2.2)
thread_safe (~> 0.1) thread_safe (~> 0.1)
tzinfo-data (1.2016.6)
tzinfo (>= 1.0.0)
uglifier (3.0.0) uglifier (3.0.0)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
warden (1.2.6) warden (1.2.6)
...@@ -159,6 +166,7 @@ GEM ...@@ -159,6 +166,7 @@ GEM
PLATFORMS PLATFORMS
ruby ruby
x86-mingw32
DEPENDENCIES DEPENDENCIES
byebug byebug
......
...@@ -5,18 +5,29 @@ class CandidatesController < ApplicationController ...@@ -5,18 +5,29 @@ class CandidatesController < ApplicationController
render "candidates/index.html.erb" render "candidates/index.html.erb"
end end
def show def edit
@candidate = Candidate.all @candidate = Candidate.find(params[:id])
render "candidates/show.html.erb" render "candidates/edit.html.erb"
end end
def update
@candidate = Candidate.find(params[:id])
if @candidate.update(candidate_params())
redirect_to candidate_path(@candidate.id)
else
render "candidates/edit.html.erb"
end
end
def new def new
@candidate = Candidate.all @candidate = Candidate.new
render "candidates/new.html.erb" render "candidates/new.html.erb"
end end
def create def create
@candidate = Candidate.all @candidate = Candidate.new(candidate_params())
if @candidate.save if @candidate.save
redirect_to candidate_path(@candidate.id) redirect_to candidate_path(@candidate.id)
else else
...@@ -24,28 +35,18 @@ class CandidatesController < ApplicationController ...@@ -24,28 +35,18 @@ class CandidatesController < ApplicationController
end end
end end
def edit def show
@candidate = Candidate.find(params[:id])
render "posts/edit.html.erb"
end
def update
@candidate = Candidate.find(params[:id]) @candidate = Candidate.find(params[:id])
if @candidate.update(candidate_params) render "candidates/show.html.erb"
redirect_to candidate_path(@candidate.id)
else
render "candidates/edit.html.erb"
end
end end
def destroy def destroy
@candidate = Candidate.find(params[:id]) @candidate = Candidate.find(params[:id])
@post.destroy! @candidate.destroy!
redirect_to candidates_path redirect_to candidates_path
end end
def candidate_params def candidate_params
params.require(:candidate).permit! params.require(:candidate).permit!
end end
end end
\ No newline at end of file
...@@ -2,10 +2,36 @@ class PositionsController < ApplicationController ...@@ -2,10 +2,36 @@ class PositionsController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
def index def index
@positions = Position.all @positions = Position.all
render "position/index.html.erb" render "positions/index.html.erb"
end end
def new def new
@position = Position.all @position = Position.new
render "positions/new.html.erb" render "positions/new.html.erb"
end end
def create
@position = Position.new(position_params())
if @position.save
redirect_to position_path(@position.id)
else
render "candidates/new.html.erb"
end
end
def show
@position = Position.find(params[:id])
render "positions/show.html.erb"
end
def destroy
@position = Position.find(params[:id])
@position.destroy!
redirect_to positions_path
end
def position_params
params.require(:position).permit!
end
end end
class Position < ActiveRecord::Base class Position < ActiveRecord::Base
has_many :candidates
end end
<link rel"stylesheet" type="text/css" href="application.css"> <link rel"stylesheet" type="text/css" href="application.css">
<h1 style="font-family:'Droid Sans';margin-left:50px;margin-top:50px;">Election 2016</h1>
<h1 style="font-family:'Droid Sans';margin-left:50px;margin-top:50px;">
Election 2016
</h1>
<h5 style="margin-left:50px";> <h5 style="margin-left:50px";>
<%= link_to "Add Position", new_position_path %> <%= link_to "Add Position", new_position_path %>
<%= link_to "Add Candidate", new_candidate_path %> <%= link_to "Add Candidate", new_candidate_path %>
</h5> </h5>
<hr> <hr>
<!--<%= link_to "Add Candidate", new_candidate_path %>--> <% if user_signed_in? %>
<!--<%= link_to "Edit Candidate", "/candidates/:id/edit" %> --> Hello <%= current_user.email %>! Your user ID is <%= current_user.id%>.
<!--<%= link_to "Delete Candidate", "/candidates/:id", method: :delete, data: { confirm: 'Are you sure?'} %> -->
<hr>
<table width="100%">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Slogan</th>
</tr>
<% @candidates.each do |candidate| %>
<tr>
<td><%= candidate.first_name %></td>
<td><%= candidate.last_name %></td>
<td><%= candidate.slogan %></td>
<td>
<%= link_to "Show ", candidate_path(candidate.id) %> |
<%= link_to "Edit", edit_candidate_path(candidate.id) %> |
<%= link_to "Delete", candidate_path(candidate.id), method: :delete, data: { confirm: 'Are you sure?'} %>
</td>
</tr>
<% end %>
</table>
<br>
<%= link_to "Home", root_path %>
<!--<% if user_signed_in? %>
Hello User!
<% else %> <% else %>
You are not signed in. Please go to login page.
<% end %> --> <h3>
\ No newline at end of file You are not signed in. Please <%= link_to "Login", new_user_session_path %>
</h3>
<% end %>
\ No newline at end of file
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
<%= render partial: "form" %> <%= render partial: "form" %>
<%= link_to "Back", candidates_path %> <%= link_to "Back", candidates_path %>
\ No newline at end of file
<h1><%= @candidate.first_name %> <%= @candidate.last_name %></h1> <h1>
<h3><%= @candidate.slogan %></h3> <%= @candidate.first_name %>
<%= @candidate.last_name %>
</h1>
<h3> <u> Slogan</u> <br> <br>
<h4>
<%= @candidate.slogan %>
</h4>
</h3>
<hr> <hr>
<%= link_to "Back to Candidates", candidates_path %> <%= link_to "Back to Candidates", candidates_path %>
\ No newline at end of file
...@@ -9,13 +9,13 @@ ...@@ -9,13 +9,13 @@
<h6 style="margin-left:100px"> <h6 style="margin-left:100px">
<li style="margin-top:10px">Troy Ang Ko</li> <li style="margin-top:10px">Troy Ang Ko</li>
<p style="color:#66ccff;margin-top:10px; margin-left: 50px;">The malandi</p> <p style="color:#66ccff;margin-top:10px; margin-left: 50px;">The malakas sa chicks</p>
<li style="margin-top:10px">Jarod Catolico</li> <li style="margin-top:10px">Jarod Catolico</li>
<p style="color:#4dc3ff;margin-top:10px; margin-left: 50px;">The mas malandi</p> <p style="color:#4dc3ff;margin-top:10px; margin-left: 50px;">The malakas sa chicken</p>
<li style="margin-top:10px">Norence Ilicito</li> <li style="margin-top:10px">Norence Ilicito</li>
<p style="color:#33bbff;margin-top:10px; margin-left: 50px;">The sketchy</p> <p style="color:#33bbff;margin-top:10px; margin-left: 50px;">The sketchy CSS Master</p>
<li style="margin-top:10px">Jego Reyes</li> <li style="margin-top:10px">Jego Reyes</li>
<p style="color:#1ab2ff;margin-top:10px; margin-left: 50px;">The pogi</p> <p style="color:#1ab2ff;margin-top:10px; margin-left: 50px;">The pogi pero malandi</p>
</h6> </h6>
<h3 style="margin-left:100px"><%= link_to "Back", ".."%></h3> <h3 style="margin-left:100px"><%= link_to "Back", ".."%></h3>
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
<h4 style="color:#0080ff;margin-left:100px"> <h4 style="color:#0080ff;margin-left:100px">
<% if user_signed_in? %> <% if user_signed_in? %>
Hello <%= current_user.email %>! Hello <%= current_user.email %>! <br>
<%= link_to('Log Out', destroy_user_session_path, :method => :delete) %> <%= link_to('Log Out', destroy_user_session_path, :method => :delete) %>
<% else %> <% else %>
<h5 style="color:#0080ff;margin-left:100px"> <h5 style="color:#0080ff;margin-left:100px">
...@@ -27,11 +28,9 @@ ...@@ -27,11 +28,9 @@
<h4 style="margin-left:100px"><%= link_to "Candidates", candidates_path %></h4> <h4 style="margin-left:100px"><%= link_to "Candidates", candidates_path %></h4>
</div> <h4 style="margin-left:100px"><%= link_to "Positions", positions_path %></h4>
</div>
</body> </body>
<%= simple_form_for(@position) do |p| %>
<%= p.input :name, as: :select, collection: ["President", "Vice President", "Senator"] %>
<%= p.submit %>
<% end %>
<link rel"stylesheet" type="text/css" href="application.css">
<h1 style="font-family:'Droid Sans';margin-left:50px;margin-top:50px;">
Election 2016
</h1>
<h5 style="margin-left:50px";>
<%= link_to "Add Position", new_position_path %>
<%= link_to "Add Candidate", new_candidate_path %>
</h5>
<hr>
<% if user_signed_in? %>
Hello <%= current_user.email %>! Your user ID is <%= current_user.id%>.
<hr>
<table width="100%">
<tr>
<th>Position</th>
</tr>
<% @positions.each do |position| %>
<tr>
<td><%= position.name %></td>
<td>
<%= link_to "Show ", position_path(position.id) %> |
<%= link_to "Edit", edit_position_path(position.id) %> |
<%= link_to "Delete", position_path(position.id), method: :delete, data: { confirm: 'Are you sure?'} %>
</td>
</tr>
<% end %>
</table>
<br>
<%= link_to "Go to Candidates", candidates_path %> |
<%= link_to "Home", root_path %>
<% else %>
<h3>
You are not signed in. Please <%= link_to "Login", new_user_session_path %>
</h3>
<% end %>
\ No newline at end of file
<h1>Add Position</h1>
<%= render partial: "form" %>
<%= link_to "Back", candidates_path %>
\ No newline at end of file
<h1>
<%= @position.name %>
</h1>
<hr>
<%= link_to "Back to Candidates", candidates_path %>
\ No newline at end of file
Rails.application.routes.draw do Rails.application.routes.draw do
devise_for :users devise_for :users
root to: "pages#index" root to: "pages#index"
get "/about", to: "pages#about"
resources :candidates resources :candidates
get "/about", to: "pages#about"
resources :positions resources :positions
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