Create model for ratings

This commit is contained in:
ricola 2025-04-06 17:04:31 -06:00
parent 6682c8c300
commit 4b5685124c
4 changed files with 44 additions and 2 deletions

10
vote.rb
View file

@ -16,6 +16,12 @@ class Candidate < ActiveRecord::Base
end
class User < ActiveRecord::Base
has_many :ratings
end
class Rating < ActiveRecord::Base
belongs_to :user
belongs_to :candidate
end
def hash_password(password)
@ -72,6 +78,10 @@ end
get '/votes/:id' do
redirect '/login' unless current_user
@vote = Vote.find(params[:id])
@ratings = {}
@vote.candidates.each do |candidate|
@ratings[candidate] = Rating.where("user_id = ? and candidate_id = ?", current_user.id, candidate.id)[0]
end
erb :votes_show
end