From 4b3bc58474f55ff38d7eb1b48e32af4f9d98157b Mon Sep 17 00:00:00 2001 From: sto Date: Sat, 15 Mar 2025 12:52:07 +0100 Subject: [PATCH] Add allow registration switch --- app/controllers/contests_controller.rb | 2 +- app/views/contests/_form.html.slim | 13 ++++++++++--- ...0315114657_add_registration_switch_to_contest.rb | 5 +++++ db/schema.rb | 3 ++- 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20250315114657_add_registration_switch_to_contest.rb diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index 8f81438..0798be3 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -47,6 +47,6 @@ class ContestsController < ApplicationController end def contest_params - params.expect(contest: [ :name ]) + params.expect(contest: [ :name, :team, :allow_registration ]) end end diff --git a/app/views/contests/_form.html.slim b/app/views/contests/_form.html.slim index a9beb74..35fe991 100644 --- a/app/views/contests/_form.html.slim +++ b/app/views/contests/_form.html.slim @@ -4,12 +4,19 @@ .form-floating = form.text_field :name, autocomplete: "off", class: "form-control" = form.label :name, class: "required" - .row + .row.mb-3 .col .form-check.form-switch = form.check_box :team, class: "form-check-input" = form.label :team | Team contest .form-text For registration and UI display purposes - div.mt-3 - = form.submit submit_text, class: "btn btn-primary" \ No newline at end of file + .row.mb-3 + .col + .form-check.form-switch + = form.check_box :allow_registration, class: "form-check-input" + = form.label :allow_registration + .form-text Generates a registration form for this contest + .row + .col + = form.submit submit_text, class: "btn btn-primary" \ No newline at end of file diff --git a/db/migrate/20250315114657_add_registration_switch_to_contest.rb b/db/migrate/20250315114657_add_registration_switch_to_contest.rb new file mode 100644 index 0000000..08f0287 --- /dev/null +++ b/db/migrate/20250315114657_add_registration_switch_to_contest.rb @@ -0,0 +1,5 @@ +class AddRegistrationSwitchToContest < ActiveRecord::Migration[8.0] + def change + add_column :contests, :allow_registration, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index e37c780..2c79f33 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_03_15_112506) do +ActiveRecord::Schema[8.0].define(version: 2025_03_15_114657) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -45,6 +45,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_03_15_112506) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "team", default: false + t.boolean "allow_registration", default: false t.index ["user_id"], name: "index_contests_on_user_id" end