Commit 1571aa7f authored by Christiana Tan's avatar Christiana Tan

Fixed voting count

parent 6c386672
class CandidatesController < ApplicationController
before_action :authenticate_user!, except: [:index] #or except
before_action :authenticate_user!, only: [:vote] #or except
before_action :authenticate_admin!, except: [:index]
def index
@candidates = Candidate.all
end
......
class Vote < ActiveRecord::Base
belongs_to :user_id
belongs_to :candidate_id
belongs_to :user
belongs_to :candidate
end
......@@ -27,7 +27,7 @@
<td> <%= c.last_name %> </td>
<td> <%= c.nickname %></td>
<% if !admin_signed_in? %>
<td> <%= %></td>
<td> <%= c.votes.count%></td>
<% end %>
<% if admin_signed_in? %>
<td> <%= c.slogan %>
......
......@@ -15,7 +15,7 @@
</div>
<ul class="nav navbar-nav">
<li><a href="positions">View Positions</a></li>
<li><%= link_to 'View Positions', positions_path %></a></li>
</ul>
......
class CreateVotes < ActiveRecord::Migration
def change
create_table :votes do |t|
t.references :user_id, index: true, foreign_key: true
t.references :candidate_id, index: true, foreign_key: true
t.references :user, index: true, foreign_key: true
t.references :candidate, index: true, foreign_key: true
t.text :comments
t.timestamps null: false
......
......@@ -73,14 +73,14 @@ ActiveRecord::Schema.define(version: 20160712083445) do
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
create_table "votes", force: :cascade do |t|
t.integer "user_id_id"
t.integer "candidate_id_id"
t.integer "user_id"
t.integer "candidate_id"
t.text "comments"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "votes", ["candidate_id_id"], name: "index_votes_on_candidate_id_id"
add_index "votes", ["user_id_id"], name: "index_votes_on_user_id_id"
add_index "votes", ["candidate_id"], name: "index_votes_on_candidate_id"
add_index "votes", ["user_id"], name: "index_votes_on_user_id"
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