Commit c241defd authored by Galen Evilla's avatar Galen Evilla

trial2

parent 8318e661
...@@ -9,6 +9,9 @@ gem 'sqlite3' ...@@ -9,6 +9,9 @@ gem 'sqlite3'
gem 'puma', '~> 3.0' gem 'puma', '~> 3.0'
# Use SCSS for stylesheets # Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0' gem 'sass-rails', '~> 5.0'
gem 'bootstrap-sass'
gem 'autoprefixer-rails'
# Use Uglifier as compressor for JavaScript assets # Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0' gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views # Use CoffeeScript for .coffee assets and views
...@@ -22,6 +25,8 @@ gem 'jquery-rails' ...@@ -22,6 +25,8 @@ gem 'jquery-rails'
gem 'turbolinks', '~> 5' gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5' gem 'jbuilder', '~> 2.5'
gem 'sdoc', '~> 0.4.0', group: :doc
# Use Redis adapter to run Action Cable in production # Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0' # gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password # Use ActiveModel has_secure_password
...@@ -43,6 +48,6 @@ end ...@@ -43,6 +48,6 @@ end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'simple_form' gem 'devise'
gem 'devise' gem 'simple_form'
\ No newline at end of file \ No newline at end of file
...@@ -39,7 +39,12 @@ GEM ...@@ -39,7 +39,12 @@ GEM
minitest (~> 5.1) minitest (~> 5.1)
tzinfo (~> 1.1) tzinfo (~> 1.1)
arel (7.0.0) arel (7.0.0)
autoprefixer-rails (6.3.6.2)
execjs
bcrypt (3.1.11-x86-mingw32) bcrypt (3.1.11-x86-mingw32)
bootstrap-sass (3.3.6)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
builder (3.2.2) builder (3.2.2)
coffee-rails (4.2.1) coffee-rails (4.2.1)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
...@@ -68,6 +73,7 @@ GEM ...@@ -68,6 +73,7 @@ GEM
rails-dom-testing (>= 1, < 3) rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
json (1.8.3)
loofah (2.0.3) loofah (2.0.3)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.6.4) mail (2.6.4)
...@@ -85,7 +91,7 @@ GEM ...@@ -85,7 +91,7 @@ GEM
pkg-config (~> 1.1.7) 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)
puma (3.4.0) puma (3.5.0)
rack (2.0.1) rack (2.0.1)
rack-test (0.6.3) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
...@@ -113,6 +119,8 @@ GEM ...@@ -113,6 +119,8 @@ GEM
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rake (11.2.2) rake (11.2.2)
rdoc (4.2.2)
json (~> 1.4)
responders (2.2.0) responders (2.2.0)
railties (>= 4.2.0, < 5.1) railties (>= 4.2.0, < 5.1)
sass (3.4.22) sass (3.4.22)
...@@ -122,6 +130,9 @@ GEM ...@@ -122,6 +130,9 @@ GEM
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3) tilt (>= 1.1, < 3)
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
simple_form (3.2.1) simple_form (3.2.1)
actionpack (> 4, < 5.1) actionpack (> 4, < 5.1)
activemodel (> 4, < 5.1) activemodel (> 4, < 5.1)
...@@ -160,6 +171,8 @@ PLATFORMS ...@@ -160,6 +171,8 @@ PLATFORMS
x86-mingw32 x86-mingw32
DEPENDENCIES DEPENDENCIES
autoprefixer-rails
bootstrap-sass
byebug byebug
coffee-rails (~> 4.2) coffee-rails (~> 4.2)
devise devise
...@@ -168,6 +181,7 @@ DEPENDENCIES ...@@ -168,6 +181,7 @@ DEPENDENCIES
puma (~> 3.0) puma (~> 3.0)
rails (~> 5.0.0) rails (~> 5.0.0)
sass-rails (~> 5.0) sass-rails (~> 5.0)
sdoc (~> 0.4.0)
simple_form simple_form
sqlite3 sqlite3
turbolinks (~> 5) turbolinks (~> 5)
......
...@@ -13,4 +13,5 @@ ...@@ -13,4 +13,5 @@
//= require jquery //= require jquery
//= require jquery_ujs //= require jquery_ujs
//= require turbolinks //= require turbolinks
//= require bootstrap-sprockets
//= require_tree . //= require_tree .
@import "bootstrap-sprockets";
@import "bootstrap";
module Admin module Admin
class CandidatesController < ApplicationController class CandidatesController < ApplicationController
before_action :authenticate_user!
def index def index
@positions = Position.all @positions = Position.all
@candidates = Candidate.all
render "admin/candidates/index.html.erb" render "admin/candidates/index.html.erb"
end end
def show def new
@candidate = Candidate.new
render "admin/candidates/new.html.erb"
end
def edit
@candidate = Candidate.find(params[:id]) @candidate = Candidate.find(params[:id])
render "admin/candidates/show.html.erb" end
def update
@candidate = Candidate.find(params[:id])
if @candidate.update(candidate_params())
redirect_to admin_candidates_path(@candidate.id)
else
render "admin/candidates/edit.html.erb"
end
end end
def destroy def destroy
@candidate = Candidate.find(params[:id]) @candidate = Candidate.find(params[:id])
@candidate.votes.each do |v|
v.destroy!
end
@candidate.destroy! @candidate.destroy!
redirect_to admin_candidates_path redirect_to admin_candidates_path
end end
def new
@candidate = Candidate.new
render "admin/candidates/new.html.erb"
end
def create def create
@candidate = Candidate.new(candidate_params()) @candidate = Candidate.new(candidate_params())
if @candidate.save if @candidate.save
flash[:success] = 'Candidate was created!'
redirect_to admin_candidate_path(@candidate.id) redirect_to admin_candidate_path(@candidate.id)
else else
render "admin/candidates/new.html.erb" render "admin/candidates/new.html.erb"
end end
end end
def edit def show
@candidate = Candidate.find(params[:id]) @candidate = Candidate.find(params[:id])
render "admin/candidates/show.html.erb"
end 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 candidate_params def candidate_params
params.require(:candidate).permit! params.require(:candidate).permit!
end end
end end
end end
\ No newline at end of file
module Admin module Admin
class PositionsController < ApplicationController class PositionsController < ApplicationController
before_action :authenticate_user!
def index def index
@positions = Position.all @positions = Position.all
render "admin/positions/index.html.erb" render "admin/positions/index.html.erb"
end end
def show def new
@position = Position.new
render "admin/positions/new.html.erb"
end
def edit
@position = Position.find(params[:id]) @position = Position.find(params[:id])
@candidates = @position.candidates
render "admin/positions/show.html.erb"
end end
def destroy def update
@position = Positions.find(params[:id]) @position = Position.find(params[:id])
@position.destroy!
redirect_to admin_positions_path if @position.update(position_params())
redirect_to admin_positions_path(@position.id), notice: 'Success!'
else
render "admin/position/edit.html.erb"
end
end end
def new def destroy
@position = Position.new @candidate = Position.find(params[:id])
render "admin/positions/new.html.erb" @candidate.destroy!
redirect_to admin_positions_path, notice: 'Position and its candidates are deleted!'
end end
def create def create
@position = Position.new(position_params()) @position = Position.new(position_params())
if @position.save if @position.save
redirect_to admin_position_path(@position.id) redirect_to admin_position_path(@position.id), notice: 'Success!'
else else
render "admin/positions/new.html.erb" render "admin/positions/new.html.erb"
end end
end end
def edit def show
@position = Positions.find(params[:id]) @position = Position.find(params[:id])
render "admin/positions/show.html.erb"
end end
def update
@position = Positions.find(params[:id])
if @position.update(position_params())
redirect_to admin_position_path(@position.id)
else
render "admin_positions/edit.html.erb"
end
end
def position_params def position_params
params.require(:position).permit! params.require(:position).permit!
end end
end end
end end
\ No newline at end of file
class ApplicationController < ActionController::Base
before_action :configure_devise_permitted_parameters, if: :devise_controller?
protect_from_forgery with: :exception
protected
def configure_devise_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, :birthday, :gender])
end
end
\ No newline at end of file
class PagesController < ApplicationController
def index
@votes = Vote.all
@candidates = Candidate.all
@positions = Position.all
render "pages/index.html.erb"
end
end
\ No newline at end of file
module Users
class ProfileController < ApplicationController
before_action :authenticate_user!
def index
@positions = Position.all
@candidates = Candidate.all
@votes = Vote.all
render "pages/profile.html.erb"
end
end
end
module Voting
class VotesController < ApplicationController
before_action :authenticate_user!
def index
@positions = Position.all
@candidates = Candidate.all
@votes = Vote.all
render "voting/votes/index.html.erb"
end
def edit
@post = Post.find(params[:id])
end
def update
@post = Post.find(params[:id])
if @post.update(post_params())
redirect_to admin_post_path(@post.id)
else
render "admin/posts/edit.html.erb"
end
end
def new
voted_for = false
@pos = params[:id]
Position.find(@pos).candidates.each do |c|
c.votes.each do |v|
if current_user.id == v.user_id
voted_for = true
end
end
end
if voted_for == false
@votes= Vote.all
@vote = Vote.new
render "voting/votes/new.html.erb"
else
redirect_to voting_votes_path
end
end
def create
@vote = current_user.votes.build(vote_params())
if @vote.save
redirect_to voting_votes_path(@vote.id)
else
render "voting/votes/new.html.erb"
end
end
def vote_params
params.require(:vote).permit!
end
end
end
\ No newline at end of file
class Candidate < ApplicationRecord
belongs_to :position
has_many :votes, dependent: :destroy
accepts_nested_attributes_for :votes
validates :last_name, presence: true
validates :first_name, presence: true
def full_name
"#{ self.first_name } #{ self.last_name }"
end
#def male_votes
# votes.select { |vote| vote.user.gender == 'male' }
#end
#def female_votes
# votes.select { |vote| vote.user.gender == 'female' }
#end
end
class Position < ApplicationRecord
has_many :candidates, dependent: :destroy
accepts_nested_attributes_for :candidates
validates :name, presence: true, uniqueness: {case_sensitive: false}
end
class User < ApplicationRecord class User < ApplicationRecord
# Include default devise modules. Others available are: has_many :votes, dependent: :destroy
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
#def did_vote?(candidate)
# similar_votes = votes.select { |vote| vote.candidate == candidate }
# similar_votes.size > 0
#end
#has_many :candidates def full_name
"#{self.first_name} #{self.last_name}"
end
end end
class Vote < ApplicationRecord class Vote < ApplicationRecord
belongs_to :user
belongs_to :candidate
end end
<%= simple_form_for([:admin, @candidate]) do |f| %>
<%= f.input :first_name, label: 'First Name: '%>
<%= f.input :last_name, label: 'Last Name: '%>
<%= f.input :slogan, label: 'Slogan: '%>
<%= f.association :position, label: 'Position: '%>
<%= f.submit %>
<% end %>
<h1>Admin Edit Post</h1>
<%= render partial: "form" %>
<%= link_to "Back to Candidates", admin_candidates_path %>
\ No newline at end of file
<h1>Candidates</h1>
<%=link_to "Add a Candidate", new_admin_candidate_path%>
<hr>
<% @positions.each do |p| %>
<h5><%= p.name %></h5>
<ul >
<% p.candidates.each do |c|%>
<li><%=link_to c.full_name, admin_candidate_path(c.id)%></li>
<% end %>
</ul>
<% end %>
<h1>New Candidate</h1>
<%= render partial: "form" %>
<h1>Name of the Candidate: <%= @candidate.full_name%></h1>
<%=link_to "Edit", edit_admin_candidate_path(@candidate.id)%>
<br>
<%=link_to "Delete", admin_candidate_path(@candidate.id), method: :delete%>
<br>
<h3>Position: <%= @candidate.position.name %></h3>
<%
m=0
f=0
o=0
%>
<%
m=0
f=0
o=0
@candidate.votes.each do |v|
if v.user != nil
if v.user.gender=="Male"
m=m+1
else
if v.user.gender=="Female"
f=f+1
else
o=o+1
end
end
end
%>
<%end%>
<hr>
<h3>Slogan: <%= @candidate.slogan%></h3>
<hr>
<table width="100%">
<tr>
<th>Male Voters</th>
<th>Female Voters</th>
<th>Other Voters</th>
<th>Total Active Votes</th>
<th>Total Active and Inactive Casted Votes</th>
</tr>
<tr>
<td><%= m%></td>
<td><%= f%></td>
<td><%= o%></td>
<td><%= m+f+o%></td>
<td><%= @candidate.votes.count %></td>
</tr>
</table>
<hr>
<h3>Voters who voted for <%= @candidate.full_name%></h3>
<ul>
<li>
<% @candidate.votes.each do |v|%>
<%="#{v.user.full_name}"%>
<p>
Comments: <%=v.comment%>
</p>
</li>
<%end%>
</ul>
<hr>
<%= link_to "Back to Candidates", admin_candidates_path %>
\ No newline at end of file
<%= simple_form_for([:admin, @position]) do |f| %> <%= simple_form_for([:admin, @position]) do |f| %>
<%= f.input :name %> <%= f.input :name, label: 'Position Name: ' %>
<%= f.submit %> <%= f.submit %>
<% end %> <% end %>
<h1>Admin Edit Post</h1>
<%= render partial: "form" %>
<%= link_to "Back to Candidates", admin_candidates_path %>
\ No newline at end of file
<h1>Positions</h1> <h1>Positions</h1>
<%= link_to("Add New Position", new_position_path) %> <%=link_to "Add New Position", new_admin_position_path%>
<hr>
<% @positions.each do |c| %> <% @positions.each do |c| %>
<h2>(<%= c.id %>) <%= c.name %></h2> <h2>(<%= c.id %>) <%= c.name %></h2>
<ul> <ul>
<% c.candidates.each do |p| %> <% c.candidates.each do |p| %>
<li><%= link_to "#{p.first_name} #{p.last_name}" , candidate_path(p.id) %></li> <li><%= link_to "#{p.first_name} #{p.last_name}" , admin_candidate_path(p.id) %></li>
<% end %> <% end %>
</ul> </ul>
<%= link_to "View all Candidates under #{c.name}" , "/positions/#{c.id}" %>
<% end %>
<% end %>
\ No newline at end of file
<hr>
<%= link_to "View Candidates", candidates_path %>
<br>
<%= link_to "Home", root_path %>
<h1>New Position</h1>
<%= render partial: "form" %>
<h1><%= @position.name%></h1>
<%=link_to "Edit", edit_admin_position_path(@position.id)%>
<%=link_to "Delete", admin_position_path(@position.id), method: :delete%>
<br>
<h5>Candidates for <%=@position.name%></h5>
<ul>
<%@position.candidates.each do |c|%>
<li><%=link_to c.full_name, admin_candidate_path(c.id)%></li>
<%end%>
</ul>
<%= link_to "<Back to Positions", admin_positions_path %>
\ No newline at end of file
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<%= f.input :first_name, required: true, autofocus: true %> <%= f.input :first_name, required: true, autofocus: true %>
<%= f.input :last_name, required: true %> <%= f.input :last_name, required: true %>
<%= f.input :birthday, :end_year => Date.today.year - 18, :start_year => 1920, :order => [ :day, :month, :year], required: true %> <%= f.input :birthday, :end_year => Date.today.year - 18, :start_year => 1920, :order => [ :day, :month, :year], required: true %>
<%= f.input :gender, as: :select, collection: ["Male", "Female"], required: true %> <%= f.input :gender, as: :select, collection: ["Male", "Female", "Other"], required: true %>
<%= f.input :email, required: true %> <%= f.input :email, required: true %>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<%= <%=
f.input :birthday, :start_year => Date.today.year - 18, :end_year => 1920, :order => [ :day, :month, :year], :required => true f.input :birthday, :start_year => Date.today.year - 18, :end_year => 1920, :order => [ :day, :month, :year], :required => true
%> %>
<%= f.input :gender, as: :select, collection: ["Male", "Female"], required: true %> <%= f.input :gender, as: :select, collection: ["Male", "Female", "Other"], required: true %>
<%= f.input :email, required: true %> <%= f.input :email, required: true %>
<%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %> <%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
<%= f.input :password_confirmation, required: true %> <%= f.input :password_confirmation, required: true %>
......
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" ><b>HalalanPH</b></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="active"><%= link_to "Home", root_path %></li>
<li><%= link_to "Candidates", admin_candidates_path %></li>
<li><%= link_to "Positions", admin_positions_path %></li>
<li><a href="/voting/votes">Vote now</li>
<%if user_signed_in?%>
<li><%= link_to "Logout", destroy_user_session_path, method: :delete %></li>
<li> Hello, <%= current_user.first_name%>!</li>
<li> <a href="/profile">My Profile</a> </li>
<%else%>
<li><%= link_to "Log-in", new_user_session_path %></li>
<li><%= link_to "Register", new_user_registration_path %></li>
<%end%>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>HalalanPH</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= render '/layouts/navbar' %>
<div class="main-page" style="margin-top:40px;">
<%= yield %>
</div>
</body>
</html>
<h1>HalalanPH</h1>
<%@positions.each do |p|%>
<h4><%=p.name%></h4>
<table>
<thead>
<td>&nbsp;</td>
<td>Name</td>
<td>Slogan</td>
<td>Votes</td>
<td>&nbsp;</td>
</thead>
<%total = 0%>
<%p.candidates.each do |c|%>
<%total = total+c.votes.count%>
<%end%>
<%p.candidates.each do |c|%>
<tr>
<td></td>
<td><%=link_to c.full_name, admin_candidate_path(c.id)%></td>
<td><%=c.slogan%></td>
<td><%=c.votes.count%></td>
<td><progress value="<%=c.votes.count%>" max="<%=total%>" ></td>
</tr>
<%end%>
</table>
<%end%>
\ No newline at end of file
<h2>Hey <%=current_user.first_name%>!</h2>
<br>
You Voted for:
<br>
<ul>
<%current_user.votes.each do |v|%>
<li>
<%="#{v.candidate.position.name}: #{v.candidate.full_name}"%>
<p>
Comments: <%=v.comment%>
</p>
</li>
<%end%>
</ul>
\ No newline at end of file
<%
if @pos == nil
@pos = 0..99
else
end
%>
<%= simple_form_for([:voting, @vote]) do |f| %>
I cast my vote for
<%= f.association :candidate, collection: Candidate.where(position_id:@pos), label_method: :full_name, value_method: :id %>
<%= f.input :comment, label: 'Comment:'%>
<%= f.submit %>
<% end %>
<h1>Admin Edit Post</h1>
<%= render partial: "form" %>
<%= link_to "Back to Posts", admin_posts_path %>
\ No newline at end of file
<h1>Votes</h1>
<h2>Hello, <%= current_user.full_name %>!</h2>
<hr>
<h4>Vote now for:</h4>
<ul>
<%@positions.each do |p|%>
<li><%=p.name%><br>
<%voted_for = false%>
<% p.candidates.each do |c|%>
<%c.votes.each do |v|%>
<%if v.user_id == current_user.id%>
You have already voted for <%= v.candidate.full_name%>
<%voted_for = true%>
<% end %>
<%end%>
<% end %>
</ol>
<%if !voted_for%>
<%=link_to "Vote for a #{p.name}", "/voting/new/#{p.id}" %>
<%else%>
<%end%>
</li>
<%end%>
</ul>
<hr>
<br>
\ No newline at end of file
<h1>Vote</h1>
<%= render partial: "form" %>
<%= link_to "Back to Votes", voting_votes_path %>
<h1><%= @post.title %></h1>
<h3><%= @post.published_at %></h3>
<p>
<%= @post.content %>
</p>
<hr>
<%= link_to "Back to Posts", admin_posts_path %>
...@@ -6,7 +6,7 @@ require 'rails/all' ...@@ -6,7 +6,7 @@ require 'rails/all'
# you've limited to :test, :development, or :production. # you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups) Bundler.require(*Rails.groups)
module Poller module Halalan
class Application < Rails::Application class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers
......
...@@ -54,7 +54,7 @@ Rails.application.configure do ...@@ -54,7 +54,7 @@ Rails.application.configure do
# Use a real queuing backend for Active Job (and separate queues per environment) # Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque # config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "Poller_#{Rails.env}" # config.active_job.queue_name_prefix = "Halalan_#{Rails.env}"
config.action_mailer.perform_caching = false config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors. # Ignore bad email addresses and do not raise email delivery errors.
......
...@@ -6,7 +6,7 @@ Devise.setup do |config| ...@@ -6,7 +6,7 @@ Devise.setup do |config|
# confirmation, reset password and unlock tokens in the database. # confirmation, reset password and unlock tokens in the database.
# Devise will use the `secret_key_base` as its `secret_key` # Devise will use the `secret_key_base` as its `secret_key`
# by default. You can change it below and use your own secret key. # by default. You can change it below and use your own secret key.
# config.secret_key = 'e005fd0494fcf6701b788857241622a3c0e503f706817ed0a7ef2b45966116ae166f0fe5bacee63c6f490fd3b804a33c5eb0ecb9d05a28cd76ced85c31b9a291' # config.secret_key = '4d0ed2f5edaa904c424f15378a80db013fed17b738793d39b916f45b0fe7406b5f5c6b05ca04db20816944fe9762525faa1223e7c3bf783e4e9de757044d062b'
# ==> Mailer Configuration # ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer, # Configure the e-mail address which will be shown in Devise::Mailer,
...@@ -108,7 +108,7 @@ Devise.setup do |config| ...@@ -108,7 +108,7 @@ Devise.setup do |config|
config.stretches = Rails.env.test? ? 1 : 11 config.stretches = Rails.env.test? ? 1 : 11
# Set up a pepper to generate the hashed password. # Set up a pepper to generate the hashed password.
# config.pepper = '16d2b0c61cc20e454a605e101525687309d237b866e673e50d5037b78bccbff7bfaeb923b0b06712b759e1a4e388f103e1056fc3bd2acec5a54571516438584f' # config.pepper = 'b3168207f12ca87dddd5f19c5de9a58c6b3ae027e7edd3f08eed4943585f9c363fd74d10688f05e3c17171439ccf2436a358b6b056c13cadd472bba56107790a'
# Send a notification email when the user's password is changed # Send a notification email when the user's password is changed
# config.send_password_change_notification = false # config.send_password_change_notification = false
......
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, key: '_Poller_session' Rails.application.config.session_store :cookie_store, key: '_Halalan_session'
Rails.application.routes.draw do
root 'pages#index'
devise_for :users
resources :users
get "/profile", to: "users/profile#index"
get "/voting/new/:id", to: "voting/votes#new"
namespace :voting do
resources :votes
end
namespace :admin do
resources :candidates
resources :positions
end
end
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
# if you're sharing your code publicly. # if you're sharing your code publicly.
development: development:
secret_key_base: e325ec50f59f5d0702dc39ab4f84569661831a0173cf6ddc9287e79fd2f8552611c657200e3b8f6d775ea4ce0f781ca8b8786a3e2a14a7d593b939426508752c secret_key_base: a120a184be8ba8273b612eff989817990858da2d03aa1067d95b199fa1fcd284a96896274307d0b1f17ef5570ce8a18de50bacc4d80f06dd77f995db00215189
test: test:
secret_key_base: c8100265b6849617b6fe673730e6a36d11bc6a6a517ec05e88767f37a6b6bac844e4e8aa81a916e27f9c17d92153a38822b2455960c1fbf3feb3c2cafdb5f5e2 secret_key_base: bcac3744318e5dbcb62954cfa6096a1d8bc67aacebe21683b14533d122575f050e6085f11cc445572f27af3dfda29a9b2063a4367df82ed72847e5dbd6205bf0
# Do not keep production secrets in the repository, # Do not keep production secrets in the repository,
# instead read values from the environment. # instead read values from the environment.
......
...@@ -4,7 +4,7 @@ class CreateCandidates < ActiveRecord::Migration[5.0] ...@@ -4,7 +4,7 @@ class CreateCandidates < ActiveRecord::Migration[5.0]
t.string :first_name t.string :first_name
t.string :last_name t.string :last_name
t.text :slogan t.text :slogan
t.integer :position_id t.references :position, foreign_key: true
t.timestamps t.timestamps
end end
......
class CreateVotes < ActiveRecord::Migration[5.0] class CreateVotes < ActiveRecord::Migration[5.0]
def change def change
create_table :votes do |t| create_table :votes do |t|
t.integer :user_id t.references :user, foreign_key: true
t.integer :candidate_id t.references :candidate, foreign_key: true
t.text :comments t.text :comment
t.timestamps t.timestamps
end end
......
class AddFieldsToUsers < ActiveRecord::Migration[5.0] class AddFieldsToUser < ActiveRecord::Migration[5.0]
def change def change
add_column :users, :first_name, :string add_column :users, :first_name, :string
add_column :users, :last_name, :string add_column :users, :last_name, :string
......
class EditFieldToUsers < ActiveRecord::Migration[5.0] class EditFieldsToUser < ActiveRecord::Migration[5.0]
def change def change
remove_column :users, :birthdate remove_column :users, :birthdate
add_column :users, :birthday, :date add_column :users, :birthday, :date
......
class AddRolesToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :role, :string, :default => 'user'
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160718122513) do ActiveRecord::Schema.define(version: 20160719111009) do
create_table "candidates", force: :cascade do |t| create_table "candidates", force: :cascade do |t|
t.string "first_name" t.string "first_name"
...@@ -19,33 +19,33 @@ ActiveRecord::Schema.define(version: 20160718122513) do ...@@ -19,33 +19,33 @@ ActiveRecord::Schema.define(version: 20160718122513) do
t.integer "position_id" t.integer "position_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "user_id" t.index ["position_id"], name: "index_candidates_on_position_id"
end end
create_table "positions", force: :cascade do |t| create_table "positions", force: :cascade do |t|
t.string "name" t.string "name"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "user_id"
end end
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: "", null: false
t.string "reset_password_token" t.string "reset_password_token"
t.datetime "reset_password_sent_at" t.datetime "reset_password_sent_at"
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at" t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at" t.datetime "last_sign_in_at"
t.string "current_sign_in_ip" t.string "current_sign_in_ip"
t.string "last_sign_in_ip" t.string "last_sign_in_ip"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "first_name" t.string "first_name"
t.string "last_name" t.string "last_name"
t.string "gender" t.string "gender"
t.date "birthday" t.date "birthday"
t.string "role", default: "user"
t.index ["email"], name: "index_users_on_email", unique: true t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end end
...@@ -53,9 +53,11 @@ ActiveRecord::Schema.define(version: 20160718122513) do ...@@ -53,9 +53,11 @@ ActiveRecord::Schema.define(version: 20160718122513) do
create_table "votes", force: :cascade do |t| create_table "votes", force: :cascade do |t|
t.integer "user_id" t.integer "user_id"
t.integer "candidate_id" t.integer "candidate_id"
t.text "comments" t.text "comment"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["candidate_id"], name: "index_votes_on_candidate_id"
t.index ["user_id"], name: "index_votes_on_user_id"
end end
end end
...@@ -4,10 +4,10 @@ one: ...@@ -4,10 +4,10 @@ one:
first_name: MyString first_name: MyString
last_name: MyString last_name: MyString
slogan: MyText slogan: MyText
position_id: 1 position: one
two: two:
first_name: MyString first_name: MyString
last_name: MyString last_name: MyString
slogan: MyText slogan: MyText
position_id: 1 position: two
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one: one:
user_id: 1 user: one
candidate_id: 1 candidate: one
comments: MyText comment: MyText
two: two:
user_id: 1 user: two
candidate_id: 1 candidate: two
comments: MyText comment: MyText
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*/
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
end
class CandidatesController < ApplicationController
def index
@positions = Position.all
@candidates = Candidate.all
render "candidates/index.html.erb"
end
def show
@candidate = Candidate.find(params[:id])
#@user = @candidate.user
#@users = User.all
render "candidates/show.html.erb"
end
def destroy
@candidate = Candidate.find(params[:id])
@candidate.destroy!
redirect_to candidates_path
end
def new
@candidate = Candidate.new
render "candidates/new.html.erb"
end
def create
#@candidate = current_user.candidates.new(candidate_params)
@candidate = Candidate.new(candidate_params())
#@user = current_user
#@users = User.all
if @candidate.save
flash[:success] = 'Candidate was created!'
redirect_to candidate_path(@candidate.id)
else
render "candidates/new.html.erb"
end
end
def edit
@candidate = Candidate.find(params[:id])
#@user = @candidate.user
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 candidate_params
params.require(:candidate).permit!
end
end
class PagesController < ApplicationController
def index
@candidates = Candidate.all
@positions = Position.all
@users = User.all
@votes = Vote.all
render "pages/index.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 show
@position = Position.find(params[:id])
@candidates = @position.candidates
#@user = @position.user
#@users = User.all
render "positions/show.html.erb"
end
def destroy
@position = Positions.find(params[:id])
@position.destroy!
redirect_to positions_path
end
def new
@position = Position.new
render "positions/new.html.erb"
end
def create
#@position = current_user.positions.new(position_params)
@position = Position.new(position_params())
#@user = current_user
#@users = User.all
if @position.save
redirect_to position_path(@position.id)
else
render "positions/new.html.erb"
end
end
def edit
@position = Positions.find(params[:id])
#@user = @position.user
end
def update
@position = Positions.find(params[:id])
if @position.update(position_params())
redirect_to position_path(@position.id)
else
render "positions/edit.html.erb"
end
end
def position_params
params.require(:position).permit!
end
end
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
render "users/show.html.erb"
end
def profile
@user = User.find(params[:id])
render "users/profile.html.erb"
end
end
class Candidate < ApplicationRecord
validates :first_name, presence: true, uniqueness: true
validates :last_name, presence: true
validates :slogan, presence: true, uniqueness: true
belongs_to :position
#belongs_to :user
end
class Position < ApplicationRecord
validates :name, presence: true, uniqueness: true
has_many :candidates
end
<%= simple_form_for([:admin, @candidate]) do |f| %>
<%= f.input :first_name, label: 'First Name: '%>
<%= f.input :last_name, label: 'Last Name: '%>
<%= f.input :slogan, label: 'Slogan: '%>
<%= f.association :position, label: 'Position: '%>
<%= f.submit %>
<% end %>
<h1>Edit Candidate</h1>
<% if user_signed_in? %>
Hello Admin!
<%= render partial: "form" %>
<% else %>
You are not signed in. Please go to login page.
<%= link_to Login, new_user_session_path %>
<% end %>
<%= link_to "Back to List of Candidates", admin_candidates_path %>
\ No newline at end of file
<h1>2016 Election Candidates</h1>
<%= link_to("New Candidate", new_admin_candidate_path) %>
<hr>
<table width="100%">
<tr>
<th>Name</th>
<th>Slogan</th>
<th>Position</th>
<th>Actions</th>
</tr>
<% @candidates.each do |c| %>
<tr align="center">
<td><%= c.first_name %> <%= c.last_name %></td>
<td><%= c.slogan %></td>
<td><%= c.position.name %></td>
<td>
<%= link_to "Show", admin_candidate_path(c.id) %>
<%= link_to "Edit", edit_admin_candidate_path(c.id) %>
<%= link_to "Delete", admin_candidate_path(c.id), method: :delete, data: { confirm: 'Are you sure?' } %>
</td>
</tr>
<% end %>
</table>
<hr>
<hr>
<%= link_to "Home", root_path %>
<br>
<%= link_to "View Positions", admin_positions_path %>
\ No newline at end of file
<h1>Add New Candidate</h1>
<% if user_signed_in? %>
Hello Admin!
<%= render partial: "form" %>
<% else %>
You are not signed in. Please go to login page.
<%= link_to Login, new_user_session_path %>
<% end %>
<%= link_to "Back to List of Candidates", admin_candidates_path %>
\ No newline at end of file
<h1><%= @candidate.first_name %> <%= @candidate.last_name %></h1>
<h3>Position: <%= @candidate.position.name%> </h3>
<h3>Slogan:</h3>
<p>
<%= @candidate.slogan %>
</p>
<hr>
<%= link_to "Back to Candidates", admin_candidates_path %>
<h1>Edit Position</h1>
<% if user_signed_in? %>
Hello Admin!
<%= render partial: "form" %>
<% else %>
You are not signed in. Please go to login page.
<%= link_to Login, new_user_session_path %>
<% end %>
<%= link_to "Back to List of Positions", admin_postitions_path %>
\ No newline at end of file
<h1>2016 Elections Positions</h1>
<% @positions.each do |c| %>
<h2>(<%= c.id %>) <%= c.name %></h2>
<%= link_to "Edit Position", edit_admin_position_path(c.id) %>
<%= link_to "Delete Position", admin_position_path(c.id), method: :delete, data: { confirm: 'Are you sure?' } %>
<ul>
<% c.candidates.each do |p| %>
<li><%= link_to "#{p.first_name} #{p.last_name}" , admin_candidate_path(p.id) %></li>
<% end %>
</ul>
<%= link_to "View all Candidates under #{c.name}" , "admin/positions/#{c.id}" %>
<%= link_to("Add New Candidate", new_admin_candidate_path) %>
<% end %>
<hr>
<%= link_to("Add New Position", new_admin_position_path) %>
<hr>
<%= link_to "View Candidates", admin_candidates_path %>
<br>
<%= link_to "Home", root_path %>
<h1>Add New Position</h1>
<% if user_signed_in? %>
Hello Admin!
<%= render partial: "form" %>
<% else %>
You are not signed in. Please go to login page.
<%= link_to Login, new_user_session_path %>
<% end %>
<%= link_to "Back to List of Positions", admin_positions_path %>
\ No newline at end of file
<h1>Position: <%= @position.name %></h1>
<h2>Candidates:</h2>
<ul>
<% @candidates.each do |c| %>
<li><%= link_to "#{p.first_name} #{p.last_name}", admin_candidate_path(p.id) %></li>
<% end %>
</ul>
<hr>
<%= link_to "Back to List of Positions", admin_positions_path %>
\ No newline at end of file
<%= simple_form_for @candidate do |f| %>
<%= f.input :first_name, label: 'First Name: '%>
<%= f.input :last_name, label: 'Last Name: '%>
<%= f.input :slogan, label: 'Slogan: '%>
<%= f.association :position, label: 'Position: '%>
<%= f.submit %>
<% end %>
<h1>Edit Candidate</h1>
<% if user_signed_in? %>
Hello User!
<%= render partial: "form" %>
<% else %>
You are not signed in. Please go to login page.
<%= link_to Login, new_user_session_path %>
<% end %>
<%= link_to "Back to List of Candidates", candidates_path %>
\ No newline at end of file
<h1>Candidates</h1>
<%= link_to("New Candidate", new_candidate_path) %>
<hr>
<table width="100%">
<tr>
<th>Name</th>
<th>Slogan</th>
<th>Position</th>
<th>Actions</th>
</tr>
<% @candidates.each do |c| %>
<tr align="center">
<td><%= c.first_name %> <%= c.last_name %></td>
<td><%= c.slogan %></td>
<td><%= c.position.name %></td>
<td>
<%= link_to "Show", candidate_path(c.id) %>
</td>
</tr>
<% end %>
</table>
<hr>
<hr>
<%= link_to "Home", root_path %>
<br>
<%= link_to "View Positions", positions_path %>
\ No newline at end of file
<h1>Add New Candidate</h1>
<% if user_signed_in? %>
Hello User!
<%= render partial: "form" %>
<% else %>
You are not signed in. Please go to login page.
<%= link_to Login, new_user_session_path %>
<% end %>
<%= link_to "Back to List of Candidates", candidates_path %>
\ No newline at end of file
<h1><%= @candidate.first_name %> <%= @candidate.last_name %></h1>
<h3>Position: <%= @candidate.position.name%> </h3>
<h3>Slogan:</h3>
<p>
<%= @candidate.slogan %>
</p>
<hr>
<%= link_to "Back to Candidates", candidates_path %>
<!DOCTYPE html>
<html>
<head>
<title>Poller</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<% if user_signed_in? %>
Welcome <%= current_user.email %>!
<br>
<%= link_to "Home", root_path %> |
<%= link_to "Profile", current_user %> |
<%= link_to "Logout", destroy_user_session_path, method: :delete %>
<hr>
<% else %>
You're not signed in.
<br>
<%= link_to "Login", new_user_session_path %>
<br>
<%= link_to "Register here!", new_user_registration_path %>
<hr>
<% end %>
<%= yield %>
</body>
</html>
<h1>Poller</h1>
<%= link_to "Manage Positions Under Admin", admin_positions_path %>
<br>
<%= link_to "Manage Candidates Under Admin", admin_candidates_path %>
<% @positions.each do |c| %>
<h2>(<%= c.id %>) <%= c.name %></h2>
<ul>
<% c.candidates.each do |p| %>
<li><%= link_to "#{p.first_name} #{p.last_name}" , admin_candidate_path(p.id) %></li>
<% end %>
</ul>
<% end %>
<br>
<%= link_to "View Positions", positions_path %>
<br>
<%= link_to "View Candidates", candidates_path %>
\ No newline at end of file
<%= simple_form_for(@position) do |f| %>
<%= f.input :name, label: 'Position Name: ' %>
<%= f.submit %>
<% end %>
<h1>Edit Position</h1>
<% if user_signed_in? %>
Hello User!
<%= render partial: "form" %>
<% else %>
You are not signed in. Please go to login page.
<%= link_to Login, new_user_session_path %>
<% end %>
<%= link_to "Back to List of Positions", postitions_path %>
\ No newline at end of file
<h1>Add New Position</h1>
<% if user_signed_in? %>
Hello User!
<%= render partial: "form" %>
<% else %>
You are not signed in. Please go to login page.
<%= link_to Login, new_user_session_path %>
<% end %>
<%= link_to "Back to List of Positions", positions_path %>
\ No newline at end of file
<h1><%= @position.name %></h1>
<h2>Candidates:</h2>
<ul>
<% @candidates.each do |p| %>
<li><%= link_to "#{p.first_name} #{p.last_name}", candidate_path(p.id) %></li>
<% end %>
</ul>
<%= link_to "Add New Candidate", new_candidate_path %>
<hr>
<%= link_to "Back to Positions", positions_path %>
<h1> <%= Create a profile page that displays all the candidates that the user voted %> </h1>
\ No newline at end of file
<h1> <%= @user.first_name %> </h1>
<h2></h2>
<p>
</p>
\ No newline at end of file
Rails.application.routes.draw do
devise_for :users
resources :users, :only=> [:show]
root to: "pages#index"
resources :candidates
resources :positions
get "/positions/:id", to: "positions#show"
namespace :admin do
resources :positions
resources :candidates
end
end
class AddUserIdToUsers < ActiveRecord::Migration[5.0]
def change
add_column :candidates, :user_id, :integer
add_column :positions, :user_id, :integer
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