Correctly order participants
This commit is contained in:
parent
a33f3ff4de
commit
194c126c90
@ -15,7 +15,7 @@ class ContestsController < ApplicationController
|
|||||||
@title = I18n.t("contests.show.title", name: @contest.name)
|
@title = I18n.t("contests.show.title", name: @contest.name)
|
||||||
@action_name = t("helpers.buttons.edit")
|
@action_name = t("helpers.buttons.edit")
|
||||||
@action_path = edit_contest_path(@contest)
|
@action_path = edit_contest_path(@contest)
|
||||||
@contestants = @contest.contestants.order(:name)
|
@contestants = @contest.contestants.sort_by { |contestant| [ -contestant.completions.size, contestant.time_seconds ] }
|
||||||
@puzzles = @contest.puzzles.order(:id)
|
@puzzles = @contest.puzzles.order(:id)
|
||||||
@messages = @contest.messages.order(:time_seconds)
|
@messages = @contest.messages.order(:time_seconds)
|
||||||
set_badges
|
set_badges
|
||||||
@ -66,7 +66,7 @@ class ContestsController < ApplicationController
|
|||||||
authorize @contest
|
authorize @contest
|
||||||
|
|
||||||
@title = I18n.t("contests.scoreboard.title", name: @contest.name)
|
@title = I18n.t("contests.scoreboard.title", name: @contest.name)
|
||||||
@contestants = @contest.contestants.order(:name)
|
@contestants = @contest.contestants.sort_by { |contestant| [ -contestant.completions.size, contestant.time_seconds ] }
|
||||||
@puzzles = @contest.puzzles.order(:id)
|
@puzzles = @contest.puzzles.order(:id)
|
||||||
render :scoreboard
|
render :scoreboard
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
# display_time :string
|
# display_time :string
|
||||||
# email :string
|
# email :string
|
||||||
# name :string
|
# name :string
|
||||||
|
# time_seconds :integer
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
# contest_id :integer not null
|
# contest_id :integer not null
|
||||||
@ -22,5 +23,14 @@ class Contestant < ApplicationRecord
|
|||||||
belongs_to :contest
|
belongs_to :contest
|
||||||
has_many :completions
|
has_many :completions
|
||||||
|
|
||||||
|
before_create :initialize_time_seconds
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
|
validates :time_seconds, presence: true
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def initialize_time_seconds
|
||||||
|
self.time_seconds = 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
15
db/migrate/20250618122655_add_time_seconds_to_contestant.rb
Normal file
15
db/migrate/20250618122655_add_time_seconds_to_contestant.rb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
class AddTimeSecondsToContestant < ActiveRecord::Migration[8.0]
|
||||||
|
def change
|
||||||
|
add_column :contestants, :time_seconds, :integer
|
||||||
|
|
||||||
|
Contestant.find_each do |contestant|
|
||||||
|
contestant.time_seconds = 0
|
||||||
|
contestant.completions.each do |completion|
|
||||||
|
contestant.time_seconds += completion.time_seconds
|
||||||
|
end
|
||||||
|
contestant.save
|
||||||
|
end
|
||||||
|
|
||||||
|
change_column_null :contestants, :time_seconds, true
|
||||||
|
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.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.0].define(version: 2025_05_17_131707) do
|
ActiveRecord::Schema[8.0].define(version: 2025_06_18_122655) 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
|
||||||
@ -60,6 +60,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_05_17_131707) do
|
|||||||
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.string "display_time"
|
t.string "display_time"
|
||||||
|
t.integer "time_seconds"
|
||||||
t.index ["contest_id"], name: "index_contestants_on_contest_id"
|
t.index ["contest_id"], name: "index_contestants_on_contest_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
1
test/fixtures/contestants.yml
vendored
1
test/fixtures/contestants.yml
vendored
@ -8,6 +8,7 @@
|
|||||||
# display_time :string
|
# display_time :string
|
||||||
# email :string
|
# email :string
|
||||||
# name :string
|
# name :string
|
||||||
|
# time_seconds :integer
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
# contest_id :integer not null
|
# contest_id :integer not null
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
# display_time :string
|
# display_time :string
|
||||||
# email :string
|
# email :string
|
||||||
# name :string
|
# name :string
|
||||||
|
# time_seconds :integer
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
# contest_id :integer not null
|
# contest_id :integer not null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user