vote/veto processing

This commit is contained in:
Mark Moser
2016-11-19 16:34:48 -06:00
parent 5845f76e1d
commit e0f5e482be
10 changed files with 240 additions and 1 deletions

View File

@ -16,6 +16,35 @@ class User < ApplicationRecord
save
end
# Voting
def cast_yea_on candidate
vote = votes.find_or_create_by(candidate_id: candidate.to_i)
vote.vote = :yea
vote.save
end
def cast_nay_on candidate
vote = votes.find_or_create_by(candidate_id: candidate.to_i)
vote.vote = :nay
vote.save
end
def approve_candidate candidate
candidate = Candidate.find(candidate.to_i)
vote = votes.find_or_create_by(candidate_id: candidate.to_i)
vote.veto = :approved
candidate.update_attribute(:review_status, :approved) if vote.save
end
def decline_candidate candidate
candidate = Candidate.find(candidate.to_i)
vote = votes.find_or_create_by(candidate_id: candidate.to_i)
vote.veto = :rejected
candidate.update_attribute(:review_status, :declined) if vote.save
end
# Roles
def admin?
'admin' == role