diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 0d085c4..6bf1c9e 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -1,7 +1,7 @@ class StaticPagesController < ApplicationController def my_tournaments - @tournaments = current_user.tournaments.order('updated_at desc') + @tournaments = current_user.tournaments.sort_by{|t| t.daysUntil} end def not_allowed diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 8694cad..b96e8b4 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -71,7 +71,7 @@ class TournamentsController < ApplicationController end def index - @tournaments = Tournament.all.limit(50).includes(:schools,:weights,:mats,:matches,:user,:wrestlers).order('updated_at desc') + @tournaments = Tournament.all.sort_by{|t| t.daysUntil} end def show @@ -132,7 +132,7 @@ class TournamentsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def tournament_params - params.require(:tournament).permit(:name, :address, :director, :director_email, :tournament_type, :weigh_in_ref, :user_id) + params.require(:tournament).permit(:name, :address, :director, :director_email, :tournament_type, :weigh_in_ref, :user_id, :date) end #Check for tournament owner diff --git a/app/models/tournament.rb b/app/models/tournament.rb index dd741f2..c11eee3 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -9,7 +9,15 @@ class Tournament < ActiveRecord::Base has_many :wrestlers, through: :weights has_many :matches, dependent: :destroy - + validates :date, presence: true + + def daysUntil + time = (Date.today - self.date).to_i + if time < 0 + time = time * -1 + end + time + end def resetSchoolScores schools.update_all("score = 0.0") diff --git a/app/views/static_pages/my_tournaments.html.erb b/app/views/static_pages/my_tournaments.html.erb index ad689d1..eccbf20 100644 --- a/app/views/static_pages/my_tournaments.html.erb +++ b/app/views/static_pages/my_tournaments.html.erb @@ -1,19 +1,20 @@
| Name | +Date | |||||||
|---|---|---|---|---|---|---|---|---|
| <%= tournament.name %> | +<%= tournament.date %> | <%= link_to 'Show', tournament, :class=>"btn btn-default" %>
<% if tournament_permissions(tournament) %>
<%= link_to 'Edit', edit_tournament_path(tournament), :class=>"btn btn-primary" %>
diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb
index 4d1e8ff..3b0eecc 100644
--- a/app/views/tournaments/_form.html.erb
+++ b/app/views/tournaments/_form.html.erb
@@ -27,6 +27,10 @@
<%= f.label :director_email %> <%= f.text_field :director_email %> +
+ <%= f.label :date %>
+ <%= f.date_field :date %> +
<%= f.label :tournament_type %> <%= f.select :tournament_type, @tournament.tournament_types %> diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb index 2b0e5c2..d361cea 100644 --- a/app/views/tournaments/index.html.erb +++ b/app/views/tournaments/index.html.erb @@ -1,19 +1,20 @@ Pick A Tournament<% if user_signed_in? %> <%= link_to 'New Tournament', new_tournament_path, :class=>"btn btn-success" %> <% end %> -
|