puzzle-scoreboard/app/controllers/contestants_controller.rb
sto a03907f756
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
Add completions
2025-03-20 11:12:55 +01:00

58 lines
1.2 KiB
Ruby

class ContestantsController < ApplicationController
before_action :set_contest
before_action :set_contestant, only: %i[ destroy edit update]
before_action :set_completions, only: %i[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
@title = "Edit contestant"
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 set_completions
@completions = @contestant.completions
end
def contestant_params
params.expect(contestant: [ :email, :name ])
end
end