Add contestants
Some checks are pending
CI / scan_ruby (push) Waiting to run
CI / scan_js (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run

This commit is contained in:
sto
2025-03-20 09:19:39 +01:00
parent 658c50fd04
commit 44507bb85c
18 changed files with 145 additions and 25 deletions

View File

@@ -0,0 +1,51 @@
class ContestantsController < ApplicationController
before_action :set_contest
before_action :set_contestant, only: %i[ destroy edit update]
def edit
@title = "Edit contestant"
end
def new
@contestant = Contestant.new
@title = "New contestant"
end
def create
@contestant = Contestant.new(contestant_params)
@contestant.contest_id = @contest.id
if @contestant.save
redirect_to contest_path(@contest)
else
@title = "New contestant"
render :new, status: :unprocessable_entity
end
end
def update
if @contestant.update(contestant_params)
redirect_to @contest
else
render :edit, status: :unprocessable_entity
end
end
def destroy
@contestant.destroy
redirect_to contest_path(@contest)
end
private
def set_contest
@contest = Contest.find(params[:contest_id])
end
def set_contestant
@contestant = Contestant.find(params[:id])
end
def contestant_params
params.expect(contestant: [ :email, :name ])
end
end

View File

@@ -8,6 +8,7 @@ class ContestsController < ApplicationController
def show
@title = @contest.name
@contestants = @contest.contestants
@puzzles = @contest.puzzles
set_badges
end

View File

@@ -1,13 +1,6 @@
class PuzzlesController < ApplicationController
before_action :set_contest
before_action :set_puzzle, only: %i[ edit destroy show update]
def index
@puzzles = Puzzle.all
end
def show
end
before_action :set_puzzle, only: %i[ destroy edit update]
def edit
@title = "Edit contest puzzle"