Use the friendly ID gem for contest slugs
All checks were successful
CI / scan_ruby (push) Successful in 18s
CI / scan_js (push) Successful in 10s
CI / lint (push) Successful in 11s
CI / test (push) Successful in 33s

This commit is contained in:
sto
2025-03-26 17:40:56 +01:00
parent a5d165c4b3
commit 2144c22bd9
12 changed files with 164 additions and 10 deletions

View File

@@ -84,6 +84,6 @@ class ContestsController < ApplicationController
end
def contest_params
params.expect(contest: [ :name, :team, :allow_registration, :slug ])
params.expect(contest: [ :name, :team, :allow_registration ])
end
end

View File

@@ -13,6 +13,7 @@
#
# Indexes
#
# index_contests_on_slug (slug) UNIQUE
# index_contests_on_user_id (user_id)
#
# Foreign Keys
@@ -20,12 +21,14 @@
# user_id (user_id => users.id)
#
class Contest < ApplicationRecord
belongs_to :user
extend FriendlyId
belongs_to :user
has_many :completions, dependent: :destroy
has_many :contestants, dependent: :destroy
has_many :puzzles, dependent: :destroy
friendly_id :name, use: :slugged
validates :name, presence: true
validates :slug, presence: true, uniqueness: true, format: { with: /\A(\w|-)*\z/, message: 'Only alphanumeric characters, "-" and "_" allowed.' }
end

View File

@@ -4,12 +4,6 @@
.form-floating
= form.text_field :name, autocomplete: "off", class: "form-control"
= form.label :name, class: "required"
.row.mb-3
.col
.form-floating
= form.text_field :slug, autocomplete: "off", class: "form-control"
= form.label :slug, class: "required"
.form-text This will be used for building the public scoreboard URL: https://puzzle-scoreboard.org/public/&lt;slug&gt;.
.row.mb-3
.col
.form-check.form-switch