puzzle-scoreboard/app/controllers/contests_controller.rb
sto 0cbd2e4fdc
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 puzzles to contests
2025-03-15 14:28:24 +01:00

61 lines
1.1 KiB
Ruby

class ContestsController < ApplicationController
before_action :set_contest, only: %i[ destroy edit show update ]
def index
@contests = current_user.contests
@title = "Welcome #{current_user.username}!"
end
def show
@title = @contest.name
@puzzles = @contest.puzzles
set_badges
end
def edit
@title = "Edit contest settings"
end
def new
@contest = Contest.new
@title = "New jigsaw puzzle competition"
end
def create
@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
if @contest.update(contest_params)
redirect_to @contest
else
render :edit, status: :unprocessable_entity
end
end
def destroy
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 ])
end
end