Commit 17007a01 authored by Paulo Macasaet's avatar Paulo Macasaet

magic vote

parent a8dcba67
class VotesController < ApplicationController
def index
@votes = Vote.all
@positions = Position.all
render "votes/index.html.erb"
end
def new
@vote = Vote.new
render "votes/new.html.erb"
end
def create
@vote = Vote.new(vote_params())
if @vote.save
redirect_to vote_path(@vote.id)
else
render "votes/new.html.erb"
end
end
def show
@candidate = Candidate.find(params[:id])
@vote = Vote.find(params[:id])
render "votes/show.html.erb"
end
def vote_params
params.require(:vote).permit!
end
end
\ No newline at end of file
......@@ -6,4 +6,8 @@ class Candidate < ActiveRecord::Base
belongs_to :position
has_many :votes
def to_s
"#{first_name} #{last_name}"
end
end
......@@ -4,4 +4,6 @@ class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :votes
end
class Vote < ActiveRecord::Base
belongs_to :candidate
belongs_to :user
def to_s
"#{first_name}"
end
end
......@@ -2,7 +2,7 @@
<%= link_to("Add Candidate", new_admin_candidate_path) %>
<table width="70%">
<table width="70%", align="center">
<tr>
<th>Position</th>
<th>First Name</th>
......
<h1 style="text-align:center"> Here are the Candidates </h1>
<%= link_to "See Total Vote Count", votes_path %>
<table width="70%">
<table width="70%", align="center">
<tr>
<th>Position</th>
<th>First Name</th>
......
......@@ -9,7 +9,7 @@
<%= f.input :password_confirmation, required: true %>
<%= f.input :first_name, required: true %>
<%= f.input :last_name, required: true %>
<%= f.input :birthday, required: true %>
<%= f.input :birthday, required: true, start_year: 1930, end_year: 1998 %>
<%= f.input :gender, as: :select, collection: ["Male", "Female"], required: true %>
</div>
......
<h1>Candidates</h1>
<%= link_to "The Candidates (USER)", candidates_path %>
<%= link_to "See Total Vote Count", votes_path %>
<a href = "/about"> About </a>
......
<%= simple_form_for(@vote) do |f| %>
<%= f.association :candidate %>
<%= f.input :comments %>
<%= f.submit %>
<% end %>
\ No newline at end of file
<h1>Total Votes</h1>
<%= link_to "Vote Here!", new_vote_path %>
<%= link_to "The Candidates (USER)", candidates_path %>
<% @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>
<% end %>
<%= link_to("Back to Home", root_path) %>
\ No newline at end of file
<h1>VOTE HERE</h1>
<%= render partial: "form" %>
<%= link_to "Back to Vote Summary", votes_path %>
<h1>Vote Summary</h1>
<h2>I voted for</h2>
<h4><%= @vote.id %> </h4>
<h4><%= @candidate.nickname %> </h4>
<h4><%= @vote.comments %></h4>
<%= link_to "Back to votes", votes_path %>
......@@ -4,6 +4,8 @@ Rails.application.routes.draw do
get "/about", to: "pages#about"
resources :candidates
get "/positions/:id", to: "positions#show"
resources :votes
namespace :admin do
resources :candidates
......
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