Commit 94a5cd72 authored by Jego Reyes's avatar Jego Reyes

fixed the log in page, position and candidate

parent 81edefce
......@@ -10,6 +10,15 @@ class CandidatesController < ApplicationController
render "candidates/edit.html.erb"
end
def create
@candidate = Candidate.new(candidate_params)
if @candidate.save
redirect_to candidates_path
else
redirect_to candidates_path
end
end
def update
@candidate = Candidate.find(params[:id])
......
......@@ -16,7 +16,15 @@ class PositionsController < ApplicationController
if @position.save
redirect_to position_path(@position.id)
else
render "candidates/new.html.erb"
render "positions/new.html.erb"
end
end
def update
if @poistion.update(position_params)
redirect_to positions_path
else
render positions_path
end
end
......
class Candidate < ActiveRecord::Base
belongs_to :position
validates :first_name, presence: true, uniqueness: true
validates :last_name, presence: true, uniqueness: true
validates :slogan, presence: true
belongs_to :position
validates :position, presence: true
end
class Position < ActiveRecord::Base
has_many :candidates
validates :name, presence: true, uniqueness: true
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
validates :first_name, presence: true
validates :last_name, presence: true
validates :first_name, presence: true, uniqueness: true
validates :last_name, presence: true, uniqueness: true
validates :birthday, presence: true
validates :gender, presence: true
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
......
<%= simple_form_for(@candidate) do |c| %>
<%= c.input :id %>
<%= c.input :first_name %>
<%= c.input :last_name %>
<%= c.input :slogan %>
......
......@@ -12,33 +12,35 @@
<hr>
<% if user_signed_in? %>
Hello <%= current_user.email %>! Your user ID is <%= current_user.id%>.
<h5 style="margin-left:50px;">Hello <%= current_user.email %>! Your user ID is <%= current_user.id%>.</h5>
<hr>
<table width="100%">
<table width="100%" style="margin:100px;">
<tr>
<th>Candidate ID </th>
<th>First Name</th>
<th>Last Name</th>
<th>Slogan</th>
</tr>
<% @candidates.each do |candidate| %>
<tr>
<td><%= candidate.id %></td>
<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 "Edit", edit_candidate_path(candidate.id) %> |
<%= link_to "Delete", candidate_path(candidate.id), method: :delete, data: { confirm: 'Are you sure?'} %>
<%= link_to "Delete", candidate_path(candidate.id), method: :delete, data: { confirm: 'Are you sure?'} %>
</td>
</tr>
<% end %>
</table>
<br>
<%= link_to "Home", root_path %>
<h4 style="margin:100px;"><%= link_to "Home", root_path %></h4>
<% else %>
......
......@@ -5,7 +5,7 @@
<div class="box fade-in one">
<h1 style="margin-left:100px;margin-top:300px;font-family:Droid Sans">Election 2016</h1>
<h1 style="margin-left:100px;margin-top:100px;font-family:Droid Sans">Election 2016</h1>
<h3 style="color:#0080ff;margin-left:100px">
<%= link_to "MIS 21 - B DataBAES", "/about" %>
......@@ -14,13 +14,8 @@
<h4 style="color:#0080ff;margin-left:100px">
<% if user_signed_in? %>
Hello <%= current_user.email %>! <br>
<h4 style="margin-left:100px"><%= link_to "Profile", "/profiles"%></h4>
<h4 style="margin-left:100px"><%= link_to "Profile", "/profiles"%>&nbsp;&nbsp;<%= link_to('Log Out', destroy_user_session_path, :method => :delete) %></h4>
<h4 style="margin-left:100px"><%= link_to "Candidates", candidates_path %></h4>
<h4 style="margin-left:100px"><%= link_to "Positions", positions_path %></h4>
<h4 style="margin-left:100px"><%= link_to('Log Out', destroy_user_session_path, :method => :delete) %> </h4>
<% else %>
<h5 style="color:#0080ff;margin-left:100px">
You're not signed in.
......@@ -31,12 +26,29 @@
</h4>
<table width="100%" style="margin:100px;">
<tr>
<th>Candidate ID </th>
<th>First Name</th>
<th>Last Name</th>
<th>Slogan</th>
</tr>
<% @candidates.each do |candidate| %>
<tr>
<td><%= candidate.id %></td>
<td><%= candidate.first_name %></td>
<td><%= candidate.last_name %></td>
<td><%= candidate.slogan %></td>
</tr>
<% end %>
</table>
</div>
</div>
</body>
<link rel"stylesheet" type="text/css" href="application.css">
<h1>Election 2016</h1>
<h3>Hello <%= current_user.last_name %></h3>
\ No newline at end of file
<h3>Hello <%= current_user.last_name %></h3>
<table width="100%" style="margin:100px;">
<tr>
<th>Candidate ID </th>
<th>First Name</th>
<th>Last Name</th>
<th>Slogan</th>
</tr>
<% @candidates.each do |candidate| %>
<tr>
<td><%= candidate.id %></td>
<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>
\ No newline at end of file
<h1>Edit Candidate</h1>
<%= render partial: "form" %>
<%= link_to "Back", 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