Create model for organizers
This commit is contained in:
parent
c8bfea4898
commit
abc26f733f
3 changed files with 44 additions and 2 deletions
19
vote.rb
19
vote.rb
|
|
@ -8,6 +8,8 @@ require_relative 'mj'
|
|||
class Vote < ActiveRecord::Base
|
||||
has_many :candidates
|
||||
has_many :ratings
|
||||
has_many :organizers
|
||||
has_many :users, through: :organizers
|
||||
end
|
||||
|
||||
class Candidate < ActiveRecord::Base
|
||||
|
|
@ -22,6 +24,15 @@ end
|
|||
|
||||
class User < ActiveRecord::Base
|
||||
has_many :ratings
|
||||
has_many :organizers
|
||||
has_many :votes, through: :organizers
|
||||
end
|
||||
|
||||
class Organizer < ActiveRecord::Base
|
||||
belongs_to :vote
|
||||
belongs_to :user
|
||||
validates :vote_id, uniqueness: { scope: :user_id }
|
||||
validates :user_id, uniqueness: { scope: :vote_id }
|
||||
end
|
||||
|
||||
class Rating < ActiveRecord::Base
|
||||
|
|
@ -114,6 +125,14 @@ post '/votes/:id/ratings' do
|
|||
redirect '/votes/' + vote.secure_id
|
||||
end
|
||||
|
||||
post '/votes/:id/organizers' do
|
||||
redirect '/login' unless current_user
|
||||
vote = Vote.find_by(secure_id: params[:id])
|
||||
user = User.find_by(email: params[:email])
|
||||
vote.users << user
|
||||
redirect '/votes/' + vote.secure_id
|
||||
end
|
||||
|
||||
helpers do
|
||||
def current_user
|
||||
if session[:user_id]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue