From 1f0cbee9fd13a63e58b8bbc2c130b0484a2a2625 Mon Sep 17 00:00:00 2001 From: sto Date: Sat, 15 Mar 2025 12:44:58 +0100 Subject: [PATCH] Add team switch --- app/controllers/contests_controller.rb | 16 ++++++++++++++-- app/controllers/users_controller.rb | 2 +- app/views/contests/_form.html.slim | 11 +++++++++-- app/views/contests/edit.html.slim | 1 + app/views/contests/new.html.slim | 2 +- app/views/contests/show.html.slim | 2 ++ .../20250315112506_add_team_switch_to_contest.rb | 5 +++++ db/schema.rb | 3 ++- 8 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 app/views/contests/edit.html.slim create mode 100644 db/migrate/20250315112506_add_team_switch_to_contest.rb diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index b7ac8ad..8f81438 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -1,5 +1,5 @@ class ContestsController < ApplicationController - before_action :set_contest, only: %i[ show destroy ] + before_action :set_contest, only: %i[ destroy edit show update ] def index @contests = current_user.contests @@ -7,7 +7,11 @@ class ContestsController < ApplicationController end def show - @title = "Contest: #{@contest.name}" + @title = @contest.name + end + + def edit + @title = "Edit contest settings" end def new @@ -25,6 +29,14 @@ class ContestsController < ApplicationController end end + def update + if @contest.update(contest_params) + redirect_to @contest + else + render :edit, status: :unprocessable_entity + end + end + def destroy end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index df35597..27e64b1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,5 @@ 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 @title = "All users" diff --git a/app/views/contests/_form.html.slim b/app/views/contests/_form.html.slim index 20ec444..a9beb74 100644 --- a/app/views/contests/_form.html.slim +++ b/app/views/contests/_form.html.slim @@ -1,8 +1,15 @@ = form_with model: contest do |form| - .row + .row.mb-3 .col .form-floating = form.text_field :name, autocomplete: "off", class: "form-control" = 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 - = form.submit "Create", class: "btn btn-primary" \ No newline at end of file + = form.submit submit_text, class: "btn btn-primary" \ No newline at end of file diff --git a/app/views/contests/edit.html.slim b/app/views/contests/edit.html.slim new file mode 100644 index 0000000..b15a2f5 --- /dev/null +++ b/app/views/contests/edit.html.slim @@ -0,0 +1 @@ += render "form", contest: @contest, submit_text: "Save" \ No newline at end of file diff --git a/app/views/contests/new.html.slim b/app/views/contests/new.html.slim index ba7dd39..43fa4a5 100644 --- a/app/views/contests/new.html.slim +++ b/app/views/contests/new.html.slim @@ -1 +1 @@ -= render "form", contest: @contest \ No newline at end of file += render "form", contest: @contest, submit_text: "Create" \ No newline at end of file diff --git a/app/views/contests/show.html.slim b/app/views/contests/show.html.slim index e69de29..7b403b1 100644 --- a/app/views/contests/show.html.slim +++ b/app/views/contests/show.html.slim @@ -0,0 +1,2 @@ +a.btn.btn-primary href=edit_contest_path(@contest) + | Edit \ No newline at end of file diff --git a/db/migrate/20250315112506_add_team_switch_to_contest.rb b/db/migrate/20250315112506_add_team_switch_to_contest.rb new file mode 100644 index 0000000..8ba1186 --- /dev/null +++ b/db/migrate/20250315112506_add_team_switch_to_contest.rb @@ -0,0 +1,5 @@ +class AddTeamSwitchToContest < ActiveRecord::Migration[8.0] + def change + add_column :contests, :team, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 22263c3..e37c780 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_14_145912) do +ActiveRecord::Schema[8.0].define(version: 2025_03_15_112506) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", 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.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "team", default: false t.index ["user_id"], name: "index_contests_on_user_id" end