Public scoreboard scaffold
Some checks failed
CI / scan_ruby (push) Successful in 1m28s
CI / scan_js (push) Successful in 12s
CI / lint (push) Successful in 12s
CI / test (push) Failing after 18s

This commit is contained in:
sto 2025-03-22 18:52:20 +01:00
parent 9a2a3a6f33
commit e8c3f04577
7 changed files with 44 additions and 2 deletions

View File

@ -26,4 +26,8 @@ class ApplicationController < ActionController::Base
flash[:error] = t "#{policy_name}.#{exception.query}", scope: "pundit", default: :default
redirect_back_or_to(root_path)
end
def not_found
render file: "#{Rails.root}/public/404.html", layout: false, status: :not_found
end
end

View File

@ -56,6 +56,20 @@ class ContestsController < ApplicationController
authorize @contest
end
def scoreboard
@contest = Contest.find_by(slug: params[:id])
unless @contest
skip_authorization
not_found and return
end
authorize @contest
@title = @contest.name
@contestants = @contest.contestants.order(:name)
@puzzles = @contest.puzzles.order(:id)
render :scoreboard
end
private
def set_badges

View File

@ -27,5 +27,5 @@ class Contest < ApplicationRecord
has_many :puzzles, dependent: :destroy
validates :name, presence: true
validates :slug, presence: true, format: { with: /\A(\w|-)*\z/, message: 'Only alphanumeric characters, "-" and "_" allowed.' }
validates :slug, presence: true, uniqueness: true, format: { with: /\A(\w|-)*\z/, message: 'Only alphanumeric characters, "-" and "_" allowed.' }
end

View File

@ -26,4 +26,8 @@ class ContestPolicy < ApplicationPolicy
def destroy?
record.user.id == user.id || user.admin?
end
def scoreboard?
true
end
end

View File

@ -0,0 +1,18 @@
table.table.table-striped.table-hover
thead
tr
th scope="col"
| Rank
th scope="col"
| Name
th scope="col"
| Completed puzzles
tbody
- @contestants.each_with_index do |contestant, index|
tr scope="row"
td
= index + 1
td
= contestant.name
td
= contestant.completions.length

View File

@ -14,7 +14,7 @@
| Edit contest
p
|> Public scoreboard:
= link_to root_url + "public/#{@contest.slug}"
= link_to root_url + "public/#{@contest.slug}", root_url + "public/#{@contest.slug}"
.row.mb-4
.col-6

View File

@ -16,4 +16,6 @@ Rails.application.routes.draw do
resources :passwords, param: :token
resource :session
resources :users
get "public/:id", to: "contests#scoreboard"
end