Public scoreboard scaffold
This commit is contained in:
parent
9a2a3a6f33
commit
e8c3f04577
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -26,4 +26,8 @@ class ContestPolicy < ApplicationPolicy
|
||||
def destroy?
|
||||
record.user.id == user.id || user.admin?
|
||||
end
|
||||
|
||||
def scoreboard?
|
||||
true
|
||||
end
|
||||
end
|
||||
|
18
app/views/contests/scoreboard.html.slim
Normal file
18
app/views/contests/scoreboard.html.slim
Normal 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
|
@ -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
|
||||
|
@ -16,4 +16,6 @@ Rails.application.routes.draw do
|
||||
resources :passwords, param: :token
|
||||
resource :session
|
||||
resources :users
|
||||
|
||||
get "public/:id", to: "contests#scoreboard"
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user