puzzle-scoreboard/app/controllers/contestants_controller.rb
sto a5d165c4b3
All checks were successful
CI / scan_ruby (push) Successful in 17s
CI / scan_js (push) Successful in 11s
CI / lint (push) Successful in 12s
CI / test (push) Successful in 41s
Save display times in the db
2025-03-26 17:00:06 +01:00

68 lines
1.3 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
authorize @contest
@title = "Contestant"
end
def new
authorize @contest
@contestant = Contestant.new
@title = "New contestant"
end
def create
authorize @contest
@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
authorize @contest
if @contestant.update(contestant_params)
redirect_to @contest
else
@title = "Contestant"
render :edit, status: :unprocessable_entity
end
end
def destroy
authorize @contest
@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.order(:time_seconds)
end
def contestant_params
params.expect(contestant: [ :email, :name ])
end
end