Add team switch
Some checks are pending
CI / scan_ruby (push) Waiting to run
CI / scan_js (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run

This commit is contained in:
sto 2025-03-15 12:44:58 +01:00
parent 1dbb495c3b
commit 1f0cbee9fd
8 changed files with 35 additions and 7 deletions

View File

@ -1,5 +1,5 @@
class ContestsController < ApplicationController class ContestsController < ApplicationController
before_action :set_contest, only: %i[ show destroy ] before_action :set_contest, only: %i[ destroy edit show update ]
def index def index
@contests = current_user.contests @contests = current_user.contests
@ -7,7 +7,11 @@ class ContestsController < ApplicationController
end end
def show def show
@title = "Contest: #{@contest.name}" @title = @contest.name
end
def edit
@title = "Edit contest settings"
end end
def new def new
@ -25,6 +29,14 @@ class ContestsController < ApplicationController
end end
end end
def update
if @contest.update(contest_params)
redirect_to @contest
else
render :edit, status: :unprocessable_entity
end
end
def destroy def destroy
end end

View File

@ -1,5 +1,5 @@
class UsersController < ApplicationController class UsersController < ApplicationController
before_action :set_user, only: %i[ destroy edit update show ] before_action :set_user, only: %i[ destroy edit show update ]
def index def index
@title = "All users" @title = "All users"

View File

@ -1,8 +1,15 @@
= form_with model: contest do |form| = form_with model: contest do |form|
.row .row.mb-3
.col .col
.form-floating .form-floating
= form.text_field :name, autocomplete: "off", class: "form-control" = form.text_field :name, autocomplete: "off", class: "form-control"
= form.label :name, class: "required" = form.label :name, class: "required"
.row
.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 div.mt-3
= form.submit "Create", class: "btn btn-primary" = form.submit submit_text, class: "btn btn-primary"

View File

@ -0,0 +1 @@
= render "form", contest: @contest, submit_text: "Save"

View File

@ -1 +1 @@
= render "form", contest: @contest = render "form", contest: @contest, submit_text: "Create"

View File

@ -0,0 +1,2 @@
a.btn.btn-primary href=edit_contest_path(@contest)
| Edit

View File

@ -0,0 +1,5 @@
class AddTeamSwitchToContest < ActiveRecord::Migration[8.0]
def change
add_column :contests, :team, :boolean, default: false
end
end

3
db/schema.rb generated
View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_03_14_145912) do ActiveRecord::Schema[8.0].define(version: 2025_03_15_112506) do
create_table "active_storage_attachments", force: :cascade do |t| create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "record_type", null: false t.string "record_type", null: false
@ -44,6 +44,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_03_14_145912) do
t.integer "user_id", null: false t.integer "user_id", null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.boolean "team", default: false
t.index ["user_id"], name: "index_contests_on_user_id" t.index ["user_id"], name: "index_contests_on_user_id"
end end