puzzle-scoreboard/app/controllers/contests_controller.rb
sto 9a2a3a6f33
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 public scoreboard slug & URL
2025-03-22 18:21:13 +01:00

75 lines
1.4 KiB
Ruby

class ContestsController < ApplicationController
before_action :set_contest, only: %i[ destroy edit show update ]
def index
authorize :contest
@contests = current_user.contests
@title = "Welcome #{current_user.username}!"
end
def show
authorize @contest
@title = @contest.name
@contestants = @contest.contestants.order(:name)
@puzzles = @contest.puzzles.order(:id)
set_badges
end
def edit
authorize @contest
@title = "Edit contest settings"
end
def new
authorize :contest
@contest = Contest.new
@title = "New jigsaw puzzle competition"
end
def create
authorize :contest
@contest = Contest.new(contest_params)
@contest.user_id = current_user.id
if @contest.save
redirect_to @contest
else
render :new, status: :unprocessable_entity
end
end
def update
authorize @contest
if @contest.update(contest_params)
redirect_to @contest
else
render :edit, status: :unprocessable_entity
end
end
def destroy
authorize @contest
end
private
def set_badges
@badges = []
@badges.push("team") if @contest.team
@badges.push("registration") if @contest.allow_registration
end
def set_contest
@contest = Contest.find(params[:id])
end
def contest_params
params.expect(contest: [ :name, :team, :allow_registration, :slug ])
end
end