Add team switch
This commit is contained in:
parent
1dbb495c3b
commit
1f0cbee9fd
@ -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
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
= form.submit submit_text, class: "btn btn-primary"
|
1
app/views/contests/edit.html.slim
Normal file
1
app/views/contests/edit.html.slim
Normal file
@ -0,0 +1 @@
|
||||
= render "form", contest: @contest, submit_text: "Save"
|
@ -1 +1 @@
|
||||
= render "form", contest: @contest
|
||||
= render "form", contest: @contest, submit_text: "Create"
|
@ -0,0 +1,2 @@
|
||||
a.btn.btn-primary href=edit_contest_path(@contest)
|
||||
| Edit
|
5
db/migrate/20250315112506_add_team_switch_to_contest.rb
Normal file
5
db/migrate/20250315112506_add_team_switch_to_contest.rb
Normal 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
3
db/schema.rb
generated
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user