added changes

parent c8612200
No preview for this file type
module Admin
class CandidatesController < ApplicationController
def index
@candidates = Candidate.all
render "admin/candidates/index.html.erb"
end
def edit
@candidate = Candidate.find(params[:id])
end
def update
@candidate = Candidate.find(params[:id])
if @candidate.update(candidate_params())
redirect_to admin_candidate_path(@candidate.id)
else
render "admin/candidates/edit.html.erb"
end
end
def new
@candidate = Candidate.new
render "admin/candidates/new.html.erb"
end
def create
@candidate = Candidate.new(candidate_params())
if @candidate.save
redirect_to admin_candidate_path(@candidate.id)
else
render "admin/candidates/new.html.erb"
end
end
def show
@candidate = Candidate.find(params[:id])
render "admin/candidates/show.html.erb"
end
def destroy
@candidate = Candidate.find(params[:id])
@candidate.destroy!
redirect_to admin_candidates_path
end
def candidate_params
params.require(:candidate).permit!
end
end
end
module Admin
class PositionsController < ApplicationController
def show
@position = Position.find(params[:id])
@candidates = @position.candidates
render "admin/positions/show.html.erb"
end
end
end
\ No newline at end of file
......@@ -2,36 +2,37 @@ class CandidatesController < ApplicationController
before_action :authenticate_user!
def index
@candidates = Candidate.all
render "candidates/index.html.erb"
render "admin/candidates/index.html.erb"
end
def edit
@candidate = Candidate.find(params[:id])
render "candidates/edit.html.erb"
render "admin/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
redirect_to candidate_path(@candidate.id)
else
render "admin/candidates/new.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
redirect_to candidate_path(@candidate.id)
else
render "admin/candidates/edit.html.erb"
end
end
def new
@candidate = Candidate.new
render "candidates/new.html.erb"
render "admin/candidates/new.html.erb"
end
def create
......@@ -40,13 +41,13 @@ class CandidatesController < ApplicationController
if @candidate.save
redirect_to candidate_path(@candidate.id)
else
render "candidates/new.html.erb"
render "admin/candidates/new.html.erb"
end
end
def show
@candidate = Candidate.find(params[:id])
render "candidates/show.html.erb"
render "admin/candidates/show.html.erb"
end
def destroy
......
class PagesController < ApplicationController
def index
def home
@positions = Position.all
@users = User.all
@candidates = Candidate.all
render "pages/index.html.erb"
end
def about
render "pages/about.html.erb"
end
end
\ No newline at end of file
class PositionsController < ApplicationController
before_action :authenticate_user!
def index
@positions = Position.all
render "positions/index.html.erb"
end
def new
@position = Position.new
render "positions/new.html.erb"
end
def create
@position = Position.new(position_params())
if @position.save
redirect_to position_path(@position.id)
else
render "positions/new.html.erb"
end
end
def update
if @poistion.update(position_params)
redirect_to positions_path
else
render positions_path
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
@candidates = @position.candidates
render "/admin/positions/show.html.erb"
end
......@@ -6,5 +6,9 @@ class Candidate < ActiveRecord::Base
validates :slogan, presence: true
validates :position, presence: true
has_many :votes
def to_s
"#{first_name} #{last_name}"
end
end
class Position < ActiveRecord::Base
has_many :candidates
validates :name, presence: true, uniqueness: true
has_many :candidates
end
......@@ -8,4 +8,6 @@ class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :votes
end
\ No newline at end of file
class Vote < ActiveRecord::Base
belongs_to :candidate
belongs_to :user
def to_s
"#{first_name}"
end
end
<link rel"stylesheet" type="text/css" href="application.css">
<%= simple_form_for([:admin, @candidate]) do |c| %>
<%= c.association :position %>
<%= c.input :first_name %>
<%= c.input :last_name %>
<%= c.input :nickname %>
<%= c.input :slogan %>
<%= c.submit %>
<% end %>
<link rel"stylesheet" type="text/css" href="application.css">
<h1>Edit Candidate</h1>
<%= render partial: "form" %>
<%= link_to "Back", admin_candidates_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>
<h5 style="margin-left:50px";>
Candidates
</h5>
<h5> <%= link_to "Add Candidate", new_admin_candidate_path %>
<hr>
<% if user_signed_in? %>
<h5 style="margin-left:50px;">Hello <%= current_user.email %>! Your user ID is <%= current_user.id%>.</h5>
<hr>
<table width="100%" style="margin:100px;">
<tr>
<th>Position</th>
<th>First Name</th>
<th>Last Name</th>
<th>Nickname</th>
<th>Slogan</th>
</tr>
<% @candidates.each do |c| %>
<tr>
<td><%= c.position.name %></td>
<td><%= c.first_name %></td>
<td><%= c.last_name %></td>
<td><%= c.nickname %></td>
<td><%= c.slogan %></td>
<td>
<%= link_to "Show ", candidate_path(candidate.id) %>
<%= link_to "Edit", edit_admin_candidate_path(a.id) %>
<%= link_to "Delete", admin_candidate_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>
<% end %>
\ No newline at end of file
<link rel"stylesheet" type="text/css" href="application.css">
<h1>New Candidate</h1>
<%= render partial: "form" %>
<%= link_to "Back", admin_candidates_path %>
\ No newline at end of file
<link rel"stylesheet" type="text/css" href="application.css">
<h1>
<%= @candidate.first_name %>
<%= @candidate.last_name %>
</h1>
<h3><%= @candidate.nickname %></h3>
<br>
<h3> <u> Slogan</u> <br> <br>
<h4>
<%= @candidate.slogan %>
</h4>
</h3>
<hr>
<%= link_to "Back to Candidates", admin_candidates_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">
<%= simple_form_for(@candidate) do |c| %>
<%= c.input :id %>
<%= c.input :first_name %>
<%= c.input :last_name %>
<%= c.input :slogan %>
<%= c.submit %>
<%= simple_form_for(@candidate) do |f| %>
<%= f.association :position %>
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.input :nickname %>
<%= f.input :slogan %>
<%= f.submit %>
<% end %>
<link rel"stylesheet" type="text/css" href="application.css">
<h1>Edit Candidate</h1>
<%= render partial: "form" %>
<%= link_to "Back", candidates_path %>
<%= link_to "Back to Candidates", candidates_path %>
<link rel"stylesheet" type="text/css" href="application.css">
<h1 style="text-align:center"> Here are the Candidates </h1>
<h1 style="font-family:'Droid Sans';margin-left:50px;margin-top:50px;">
Election 2016
</h1>
<%= link_to "See Total Vote Count", votes_path %>
<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? %>
<h5 style="margin-left:50px;">Hello <%= current_user.email %>! Your user ID is <%= current_user.id%>.</h5>
<hr>
<table width="100%" style="margin:100px;">
<table width="70%", align="center">
<tr>
<th>Candidate ID </th>
<th>Position</th>
<th>First Name</th>
<th>Last Name</th>
<th> Nickname</th>
<th>Slogan</th>
</tr>
<% @candidates.each do |candidate| %>
<% @candidates.each do |a| %>
<tr>
<td><%= candidate.id %></td>
<td><%= candidate.first_name %></td>
<td><%= candidate.last_name %></td>
<td><%= candidate.slogan %></td>
<td><%= a.position.name %></td>
<td><%= a.first_name %></td>
<td><%= a.last_name %></td>
<td><%= a.nickname %></td>
<td><%= a.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?'} %>
<%= link_to "Show", candidate_path(a.id) %>
</td>
</tr>
<% end %>
</table>
<br>
<h4 style="margin:100px;"><%= link_to "Home", root_path %></h4>
<% else %>
<%= link_to("Back to Home", root_path) %>
<h3>
You are not signed in. Please <%= link_to "Login", new_user_session_path %>
</h3>
<% end %>
\ No newline at end of file
<link rel"stylesheet" type="text/css" href="application.css">
<h1>New Candidate</h1>
<%= render partial: "form" %>
<%= link_to "Back", candidates_path %>
\ No newline at end of file
<%= link_to "Back to Candidates", candidates_path %>
<link rel"stylesheet" type="text/css" href="application.css">
<h1>
<%= @candidate.first_name %>
<%= @candidate.last_name %>
</h1>
<h3> <u> Slogan</u> <br> <br>
<h4>
<%= @candidate.slogan %>
</h4>
</h3>
<h1><%= @candidate.nickname %></h1>
<br>
<ul>
<li><%= @candidate.first_name %></li>
<li><%= @candidate.last_name %></li>
<li><%= @candidate.slogan %></li>
</ul>
<hr>
<%= link_to "Back to Candidates", candidates_path %>
\ No newline at end of file
<%= link_to "Back to List", candidates_path %>
<link rel"stylesheet" type="text/css" href="application.css">
<link rel ="stylesheet" type="text/css" href="application.css">
<h2>Resend confirmation instructions</h2>
......
......@@ -10,7 +10,7 @@
<%= f.input :first_name, required: true, autofocus: true %>
<%= f.input :last_name, required: true, autofocus: true %>
<%= f.input :birthday, required: true, autofocus: true %>
<%= f.input :gender, required: true, as: :select, :collection => ['Female', 'Male'] autofocus: true %>
<%= f.input :gender, required: true, as: :select, :collection => ['Female', 'Male'], autofocus: true %>
<%= f.input :email, required: true, autofocus: true %>
<%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
<%= f.input :password_confirmation, required: true %>
......
......@@ -9,7 +9,6 @@
<body>
<%= yield %>
</body>
......
......@@ -47,7 +47,19 @@
<% end %>
</table>
<%= link_to "See Total Vote Count", votes_path %>
<hr>
<% @positions.each do |c| %>
<h2>(<%= c.id %>) <%= c.name %></h2>
<ul>
<% c.candidates.each do |p| %>
<li><%= link_to p.last_name, candidate_path(p.id) %></li>
<% end %>
</ul>
<%= link_to "View all candidates", "/positions/#{c.id}" %>
<% end %>
</div>
......
<link rel"stylesheet" type="text/css" href="application.css">
<h1>
<%= @position.name %>
</h1>
<hr>
<%= link_to "Back to Candidates", candidates_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">
<body>
<div class="box fade-in one">
<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" %>
</h3>
<h4 style="color:#0080ff;margin-left:100px">
<% if user_signed_in? %>
Hello <%= current_user.email %>! <br>
<h4 style="margin-left:100px">
<%= link_to "Vote", vote_path %>&nbsp;&nbsp;
<%= link_to "Votes Record", vote_history_path %>&nbsp;&nbsp;
<%= link_to("Back to Home", root_path) %>&nbsp;&nbsp;
<%= link_to('Log Out', destroy_user_session_path, :method => :delete) %> &nbsp;&nbsp;
</h4>
<% else %>
<h5 style="color:#0080ff;margin-left:100px">
You're not signed in.
<%= link_to "Login", new_user_session_path %>
<%= link_to "Register", new_user_registration_path %>
<%= link_to "Admin", admin_candidates_path %>
</h5>
<% end %>
</h4>
<table width="100%" style="margin:100px;">
<tr>
<th>Position</th>
<th>First Name</th>
<th>Last Name</th>
<th>Slogan</th>
<th>Number of Votes</th>
</tr>
<% @candidates.each do |position_id, candidates| %>
<%= Position.find(position_id).name %>
<tr>
<% candidates.each do |candidate|%>
</tr>
<tr>
<td><%= candidate.position_id %></td>
<td><%= candidate.first_name %></td>
<td><%= candidate.last_name %></td>
<td><%= candidate.slogan %></td>
</tr>
<% end %>
<% end %>
</table>
</div>
</body>
<link rel"stylesheet" type="text/css" href="application.css">
<h1>Ballot</h1>
<% @candidates.each do |position_id, candidates| %>
<%= simple_form_for(@vote, url: confirm_vote_path, method: :post) do |o| %>
<%= Position.find(position_id).name %>
<ul>
<li><%= o.association :candidate, :collection => candidates %></li>
<li><%= o.input :comments %></li>
</ul>
<%= o.button :submit, "Vote" %>
<% end %>
<%= link_to "Back", candidates_list_path %>
<% end %>
\ No newline at end of file
<link rel"stylesheet" type="text/css" href="application.css">
<h1>Voting Record of <%= current_user.first_name %> <%= current_user.last_name %> </h1>
<table>
<thead>
<th>Voted Candidate</th>
<th>Position </th>
<th>Voted On</th>
</thead>
<tbody>
<% @votes.each do |o| %>
<tr>
<td><%= o.candidate.first_name %>&nbsp<%= o.candidate.last_name %></td>
<td><%= o.candidate.position.name %></td>
<td><%= o.created_at %></td>
</tr>
<% end %>
</tbody>
</table>
Rails.application.routes.draw do
devise_for :users
root to: "pages#index"
get "/about", to: "pages#about"
get "/votingstatistic", to: "pages#statistic"
get "/profiles", to: "pages#profiles"
root to: "votes#index"
get "/about", to: "pages#about"
get "/index", to: "pages#index"
resources :candidates
resources :positions
get "/positions/:id", to: "positions#show"
get 'candidates_list', to: 'votes#index', as: :candidates_list
get '/vote', to: 'votes#vote', as: :vote
post '/confirm_vote', to: 'votes#confirm_vote', as: :confirm_vote
get '/vote_history', to: 'votes#vote_history', as: :vote_history
namespace :admin do
resources :candidates
get "/positions/:id", to: "positions#show"
end
end
class AddMoreFieldsToCandidates < ActiveRecord::Migration
def change
add_column :candidates, :nickname, :string
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160719105648) do
ActiveRecord::Schema.define(version: 20160720070947) do
create_table "candidates", force: :cascade do |t|
t.string "first_name"
......@@ -20,6 +20,7 @@ ActiveRecord::Schema.define(version: 20160719105648) do
t.integer "position_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "nickname"
end
create_table "positions", force: :cascade do |t|
......
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