candidate.rb 537 Bytes
Newer Older
Galen Evilla's avatar
Galen Evilla committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
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

21 22
  def others_votes
    votes.select { |vote| vote.user.gender == 'Others' }
Galen Evilla's avatar
Galen Evilla committed
23 24 25
  end

end