diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 421725e..a9ead2f 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -60,7 +60,7 @@ class TournamentsController < ApplicationController def team_scores @schools = @tournament.schools - @schools.sort_by{|s| s.score} + @schools.sort_by{|s| s.score}.reverse! end diff --git a/app/models/match.rb b/app/models/match.rb index dd06693..8ed960a 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -7,6 +7,8 @@ class Match < ActiveRecord::Base after_save do if self.finished == 1 advance_wrestlers + self.wrestler1.school.calcScore + self.wrestler2.school.calcScore end end diff --git a/app/models/school.rb b/app/models/school.rb index d9f2cdc..aa6a325 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -5,9 +5,6 @@ class School < ActiveRecord::Base #calculate score here - def score - calcScore - end def calcScore totalWrestlerPoints - totalDeductedPoints diff --git a/db/migrate/20151117152454_add_score_back_to_school.rb b/db/migrate/20151117152454_add_score_back_to_school.rb new file mode 100644 index 0000000..7f8310b --- /dev/null +++ b/db/migrate/20151117152454_add_score_back_to_school.rb @@ -0,0 +1,5 @@ +class AddScoreBackToSchool < ActiveRecord::Migration + def change + add_column :schools, :score, :decimal + end +end diff --git a/db/schema.rb b/db/schema.rb index 694ab0b..02f837f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151111130227) do +ActiveRecord::Schema.define(version: 20151117152454) do create_table "matches", force: :cascade do |t| t.integer "w1" @@ -37,7 +37,7 @@ ActiveRecord::Schema.define(version: 20151111130227) do add_index "matches", ["mat_id"], name: "index_matches_on_mat_id" add_index "matches", ["tournament_id"], name: "index_matches_on_tournament_id" - add_index "matches", ["w1", "w2"], name: "index_matches_on_w1_and_w2" + add_index "matches", ["w1", "w2"], name: "index_matches_on_w1_and_w2", unique: true create_table "mats", force: :cascade do |t| t.string "name" @@ -53,6 +53,7 @@ ActiveRecord::Schema.define(version: 20151111130227) do t.datetime "created_at" t.datetime "updated_at" t.integer "tournament_id" + t.decimal "score" end add_index "schools", ["tournament_id"], name: "index_schools_on_tournament_id" @@ -79,6 +80,7 @@ ActiveRecord::Schema.define(version: 20151111130227) do end add_index "tournaments", ["user_id"], name: "index_tournaments_on_user_id" + add_index "tournaments", ["weigh_in_ref"], name: "index_tournaments_on_weigh_in_ref" create_table "users", force: :cascade do |t| t.string "email", default: "", null: false @@ -122,6 +124,7 @@ ActiveRecord::Schema.define(version: 20151111130227) do t.decimal "offical_weight" end + add_index "wrestlers", ["offical_weight"], name: "index_wrestlers_on_offical_weight" add_index "wrestlers", ["weight_id"], name: "index_wrestlers_on_weight_id" end