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 ...@@ -10,6 +10,15 @@ class CandidatesController < ApplicationController
render "candidates/edit.html.erb" render "candidates/edit.html.erb"
end end
def create
@candidate = Candidate.new(candidate_params)
if @candidate.save
redirect_to candidates_path
else
redirect_to candidates_path
end
end
def update def update
@candidate = Candidate.find(params[:id]) @candidate = Candidate.find(params[:id])
......
...@@ -16,7 +16,15 @@ class PositionsController < ApplicationController ...@@ -16,7 +16,15 @@ class PositionsController < ApplicationController
if @position.save if @position.save
redirect_to position_path(@position.id) redirect_to position_path(@position.id)
else 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
end end
......
class Candidate < ActiveRecord::Base class Candidate < ActiveRecord::Base
belongs_to :position
validates :first_name, presence: true, uniqueness: true validates :first_name, presence: true, uniqueness: true
validates :last_name, presence: true, uniqueness: true validates :last_name, presence: true, uniqueness: true
validates :slogan, presence: true validates :slogan, presence: true
belongs_to :position validates :position, presence: true
end end
class Position < ActiveRecord::Base class Position < ActiveRecord::Base
has_many :candidates has_many :candidates
validates :name, presence: true, uniqueness: true
end end
class User < ActiveRecord::Base class User < ActiveRecord::Base
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
validates :first_name, presence: true validates :first_name, presence: true, uniqueness: true
validates :last_name, presence: true validates :last_name, presence: true, uniqueness: true
validates :birthday, presence: true
validates :gender, presence: true
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
......
<%= simple_form_for(@candidate) do |c| %> <%= simple_form_for(@candidate) do |c| %>
<%= c.input :id %>
<%= c.input :first_name %> <%= c.input :first_name %>
<%= c.input :last_name %> <%= c.input :last_name %>
<%= c.input :slogan %> <%= c.input :slogan %>
......
...@@ -12,33 +12,35 @@ ...@@ -12,33 +12,35 @@
<hr> <hr>
<% if user_signed_in? %> <% 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> <hr>
<table width="100%"> <table width="100%" style="margin:100px;">
<tr> <tr>
<th>Candidate ID </th>
<th>First Name</th> <th>First Name</th>
<th>Last Name</th> <th>Last Name</th>
<th>Slogan</th> <th>Slogan</th>
</tr> </tr>
<% @candidates.each do |candidate| %> <% @candidates.each do |candidate| %>
<tr> <tr>
<td><%= candidate.id %></td>
<td><%= candidate.first_name %></td> <td><%= candidate.first_name %></td>
<td><%= candidate.last_name %></td> <td><%= candidate.last_name %></td>
<td><%= candidate.slogan %></td> <td><%= candidate.slogan %></td>
<td> <td>
<%= link_to "Show ", candidate_path(candidate.id) %> | <%= 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> </td>
</tr> </tr>
<% end %> <% end %>
</table> </table>
<br> <br>
<%= link_to "Home", root_path %> <h4 style="margin:100px;"><%= link_to "Home", root_path %></h4>
<% else %> <% else %>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<div class="box fade-in one"> <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"> <h3 style="color:#0080ff;margin-left:100px">
<%= link_to "MIS 21 - B DataBAES", "/about" %> <%= link_to "MIS 21 - B DataBAES", "/about" %>
...@@ -14,13 +14,8 @@ ...@@ -14,13 +14,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 %>! <br> 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 %> <% else %>
<h5 style="color:#0080ff;margin-left:100px"> <h5 style="color:#0080ff;margin-left:100px">
You're not signed in. You're not signed in.
...@@ -31,12 +26,29 @@ ...@@ -31,12 +26,29 @@
</h4> </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> </body>
<link rel"stylesheet" type="text/css" href="application.css"> <link rel"stylesheet" type="text/css" href="application.css">
<h1>Election 2016</h1> <h1>Election 2016</h1>
<h3>Hello <%= current_user.last_name %></h3> <h3>Hello <%= current_user.last_name %></h3>
\ No newline at end of file
<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