Commit c4ba16d8 authored by Christiana Tan's avatar Christiana Tan

New update

parents e3fdc7e2 eab438a6
......@@ -37,6 +37,10 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
<<<<<<< HEAD
=======
bcrypt (3.1.11)
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
bcrypt (3.1.11-x86-mingw32)
better_errors (2.1.1)
coderay (>= 1.0.0)
......@@ -85,6 +89,12 @@ GEM
mini_portile2 (2.1.0)
minitest (5.9.0)
multi_json (1.12.1)
<<<<<<< HEAD
=======
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
nokogiri (1.6.8-x86-mingw32)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
......@@ -142,6 +152,10 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
<<<<<<< HEAD
=======
sqlite3 (1.3.11)
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
sqlite3 (1.3.11-x86-mingw32)
thor (0.19.1)
thread_safe (0.3.5)
......@@ -164,6 +178,10 @@ GEM
sprockets-rails (>= 2.0, < 4.0)
PLATFORMS
<<<<<<< HEAD
=======
ruby
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
x86-mingw32
DEPENDENCIES
......@@ -184,4 +202,8 @@ DEPENDENCIES
web-console (~> 2.0)
BUNDLED WITH
<<<<<<< HEAD
1.10.4
=======
1.12.5
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
class CandidatesController < ApplicationController
<<<<<<< HEAD
before_action :authenticate_admin!, except: [:index]
=======
before_action :authenticate_user!, only: [:vote] #or except
before_action :authenticate_admin!, except: [:index]
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
def index
@candidates = Candidate.all
end
<<<<<<< HEAD
=======
def vote
end
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
def new
@candidate = Candidate.new
end
......@@ -13,7 +24,11 @@ class CandidatesController < ApplicationController
@candidate = Candidate.new(candidate_params)
if @candidate.save
<<<<<<< HEAD
redirect_to candidates_path, notice: "User was successfully created"
=======
redirect_to candidate_path(@candidate), notice: "User was successfully created"
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
else
render 'new'
end
......@@ -23,11 +38,16 @@ class CandidatesController < ApplicationController
@candidate = Candidate.find(params[:id])
@candidate.destroy()
<<<<<<< HEAD
redirect_to candidates_path
=======
redirect_to candidate_path
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
end
def edit
<<<<<<< HEAD
@candidate = Candidate.find(params[:id])
end
......@@ -39,6 +59,12 @@ class CandidatesController < ApplicationController
else
render 'edit'
end
=======
@candidate = Candidate.find(params[:id])
end
def update
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
end
def show
......
......@@ -5,5 +5,15 @@ class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
<<<<<<< HEAD
=======
validates :email
validates :encrypted_password, presence: true
validates :first_name, presence: true
validates :last_name, presence: true
validates :birthday
validates :gender
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
end
......@@ -2,5 +2,11 @@ class Vote < ActiveRecord::Base
belongs_to :user
belongs_to :candidate
<<<<<<< HEAD
validates :candidate, presence: true, uniqueness: true
=======
validates :user_id, presence: true, uniqueness: true
validates :candidate_id, presence: true, uniqueness: true
validates :comments
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
end
<div class = "container">
<h1>Edit Candidate</h1>
<<<<<<< HEAD
=======
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
<%= render 'form' %>
</div>
\ No newline at end of file
<div class = "container">
<<<<<<< HEAD
<% @candidates.group_by(&:position).each do |p, can| %>
<h4> <%= p.name %> </h4>
<table class = "table">
......@@ -26,4 +27,59 @@
</table>
<% end %>
<%= link_to 'New Candidate', new_candidate_path, class: "btn btn-primary" %>
=======
<%#- <%= current_admin.email %>
<% @candidates.group_by(&:position).each do |p, can| %>
<h4> <%= p.name %> </h4>
<table class = "table">
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>Nickname</th>
<% if !admin_signed_in? %>
<th>Votes</th>
<% end %>
<% if admin_signed_in? %>
<th>Slogan</th>
<% end %>
</thead>
<tbody>
<% can.each do |c| %>
<tr>
<td> <%= c.first_name %> </td>
<td> <%= c.last_name %> </td>
<td> <%= c.nickname %></td>
<% if !admin_signed_in? %>
<td> <%= c.votes.count%></td>
<% end %>
<% if admin_signed_in? %>
<td> <%= c.slogan %>
<td> <%= link_to 'Show', show_candidates_path(c), class: "btn btn-primary" %></td>
<td> <%= link_to 'Edit', edit_candidates_path(c), class: "btn btn-success" %></td>
<td> <a href="/candidates/delete?id=<%= c.id %>"><button class="btn btn-danger">Delete</button></a></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<% if admin_signed_in? %>
<%= link_to 'New Candidate', new_candidates_path, class: "btn btn-primary" %>
<% end %>
<% if user_signed_in? %>
<%= link_to 'Vote', vote_candidates_path, class: "btn btn-primary" %>
<% end %>
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
</div>
\ No newline at end of file
<<<<<<< HEAD
<div class = "container">
<h1>New Candidate</h1>
<%= render 'form' %>
</div>
\ No newline at end of file
</div>
=======
<h1>New Candidate</h1>
<!--<%= form_for(@candidate) do |u| %>
<% if @candidate.errors.any? %>
<ul>
<%= @candidate.errors.full_messages.each do |message| %>
<li> <%= message %>
</li>
<% end %>
</ul>
<% end %>
<p>
<%= u.label "First Name: " %>
<%= u.text_field :first_name %>
</p>
<p>
<%= u.label "Last Name: " %>
<%= u.text_field :last_name %>
</p>
<p>
<%= u.label "Nickname: " %>
<%= u.text_field :nickname %>
</p>
<p>
<%= u.label "Slogan" %>
<%= u.text_area :slogan %>
<% if @candidate.errors.messages[:slogan].any? %>
<% end %>
</p>
<button class = "btn btn-success"> Create Candidate<% u.submit %></button>
<br>
<br>
<% end %>
<%= link_to 'Cancel', candidates_path, class: "btn btn-danger" %> -->
<%= render 'form' %>
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
......@@ -16,7 +16,10 @@
<ul class="nav navbar-nav">
<li><%= link_to 'View Positions', positions_path %></a></li>
<<<<<<< HEAD
<li><%= link_to 'View Candidates', candidates_path %></a></li>
=======
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
</ul>
......
<<<<<<< HEAD
<%= simple_form_for(@position) do |p| %>
<%= p.input :name %>
<%= p.input :number_of_winners %>
......@@ -5,3 +6,15 @@
<%= link_to 'Cancel', candidates_path, class: "btn btn-danger" %>
<% end %>
=======
<%= simple_form_for(@position) do |p| %>
<%= p.input :name %>
<%= p.input :number_of_winners %>
<button class = "btn btn-success">Create new position <% p.submit %></button>
<% end %>
<%= link_to 'Cancel', positions_path, class: "btn btn-danger" %>
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
<<<<<<< HEAD
<div class = "container">
<h1>Edit Position</h1>s
<%= render 'form' %>
</div>
\ No newline at end of file
</div>
=======
<h1>Edit Position</h1>
<%= form_for(@position, url: update_position_path(@position)) do |p| %>
<p>
<%= p.label "Name" %>
<%= p.text_field :name %>
</p>
<p>
<%= p.label "Number of Winners" %>
<%= p.text_field :number_of_winners %>
</p>
<button class = "btn btn-success">Edit position <% p.submit %></button>
<% end %>
<%= link_to 'Cancel', positions_path, class: "btn btn-danger" %>
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
<<<<<<< HEAD
<div class = "container">
<h1> List of Positions</h1>
<table class = "table">
......@@ -18,4 +19,28 @@
</tbody>
</table>
<%= link_to 'Add new position', new_position_path, class: "btn btn-primary" %>
</div>
\ No newline at end of file
</div>
=======
<h1> List of Positions</h1>
<table class = "table">
<thead>
<th>Name</th>
<th>Number of Winners</th>
</thead>
<tbody>
<% @positions.each do |c| %>
<tr>
<td> <%= c.name %> </td>
<td> <%= link_to 'Show', show_position_path(c) %> </td>
<td> <%= link_to 'Edit', edit_position_path(c) %> </td>
<td> <%= link_to 'Delete', delete_position_path(c) %> </td>
</tr>
<% end %>
</tbody>
</table>
<%= link_to 'Add new position', new_positions_path, class: "btn btn-primary" %>
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
<<<<<<< HEAD
<div class = "container">
<h1>New Position</h1>
<%= render 'form' %>
</div>
\ No newline at end of file
</div>
=======
<h1>New Position</h1>
<%= render "form"%>
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
<<<<<<< HEAD
<div class = "container">
<h1>Candidates for <%= @position.name %></h1>
......@@ -22,4 +23,32 @@
</tbody>
</table>
<%= link_to 'Back', positions_path, class: "btn btn-primary" %>
</div>
\ No newline at end of file
</div>
=======
bu<h1>Candidates for <%= @position.name %></h1>
<table class = "table">
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>Nickname</th>
<th>Slogan</th>
</thead>
<tbody>
<% @position.candidate.each do |c| %>
<tr>
<td> <%= c.first_name %> </td>
<td> <%= c.last_name %> </td>
<td> <%= c.nickname %></td>
<td> <%= c.slogan %></td>
</tr>
<% end %>
</tbody>
</table>
<%= link_to 'Back', positions_path %>
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
<<<<<<< HEAD
Rails.application.routes.draw do
resources :candidates
resources :positions
......@@ -11,4 +12,45 @@ Rails.application.routes.draw do
devise_for :users
devise_for :admins
=======
Rails.application.routes.draw do
devise_for :users
devise_for :admins
root 'candidates#index'
get '/candidates', to: 'candidates#index', as: :candidates
get '/candidates/new', to: 'candidates#new', as: :new_candidates
get '/candidates/vote', to: 'candidates#vote', as: :vote_candidates
get 'candidates/edit/:id', to: 'candidates#edit', as: :edit_candidates
get '/candidates/show/:id', to: 'candidates#show', as: :show_candidates
patch 'candidates/update/:id', to: 'candidates#update', as: :update_candidates
get '/candidates/delete', to: 'candidates#destroy', as: :delete_candidates
post '/candidates', to: 'candidates#create', as: :candidate
get 'positions', to:'positions#index', as: :positions
get 'positions/new', to:'positions#new', as: :new_positions
patch 'positions/update/:id', to: 'positions#update', as: :update_position
post 'positions', to: 'positions#create', as: :create_position
get 'positions/edit/:id', to: 'positions#edit', as: :edit_position
get 'positions/show/:id', to: 'positions#show', as: :show_position
get '/positions/delete/:id', to: 'positions#destroy', as: :delete_position
>>>>>>> eab438a60d774a5c3833f57eff50b31b57c6cd5c
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