Use the friendly ID gem for contest slugs
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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/<slug>.
|
||||
.row.mb-3
|
||||
.col
|
||||
.form-check.form-switch
|
||||
|
Reference in New Issue
Block a user