Commit b4c2dc98 authored by Bianca Tarun's avatar Bianca Tarun

Added CandidatesController, Vote model, edited Candidate, User, Vote model

parent 23be063f
class CandidatesController < ApplicationController
def index
@positions = Position.all
end
end
\ No newline at end of file
class Candidate < ActiveRecord::Base class Candidate < ActiveRecord::Base
has_many :votes validates :first_name, presence: true
belongs_to :position validates :last_name, presence: true
validates :slogan, uniqueness: true, presence: true
end end
...@@ -3,4 +3,5 @@ class User < ActiveRecord::Base ...@@ -3,4 +3,5 @@ class User < ActiveRecord::Base
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
has_many :votes
end end
class Vote < ActiveRecord::Base
belongs_to :user
belongs_to :candidate
validates :candidate_id, presence: true
end
class CreateVotes < ActiveRecord::Migration
def change
create_table :votes do |t|
t.text :comments
t.timestamps null: false
end
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
comments: MyText
two:
comments: MyText
require 'test_helper'
class VoteTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# 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