1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Added a next bout number to the mat show page on the match stats

This commit is contained in:
2025-01-20 11:41:07 -05:00
parent cc62e1c2f1
commit 60814fdd94
4 changed files with 76 additions and 4 deletions

View File

@@ -22,6 +22,7 @@ class MatchesController < ApplicationController
end
def stat
# @show_next_bout_button = false
if params[:match]
@match = Match.where(:id => params[:match]).includes(:wrestlers).first
end
@@ -60,7 +61,9 @@ class MatchesController < ApplicationController
respond_to do |format|
if @match.update(match_params)
if session[:return_path]
format.html { redirect_to session.delete(:return_path), notice: 'Match was successfully updated.' }
sanitized_return_path = sanitize_return_path(session[:return_path])
format.html { redirect_to sanitized_return_path, notice: 'Match was successfully updated.' }
session.delete(:return_path) # Remove the session variable
else
format.html { redirect_to "/tournaments/#{@match.tournament.id}", notice: 'Match was successfully updated.' }
end
@@ -75,7 +78,7 @@ class MatchesController < ApplicationController
end
end
end
end
end
private
@@ -92,4 +95,12 @@ class MatchesController < ApplicationController
def check_access
authorize! :manage, @match.tournament
end
def sanitize_return_path(path)
uri = URI.parse(path)
params = Rack::Utils.parse_nested_query(uri.query)
params.delete("bout_number") # Remove the bout_number param
uri.query = params.to_query.presence # Rebuild the query string or set it to nil if empty
uri.to_s # Return the full path as a string
end
end

View File

@@ -6,7 +6,18 @@ class MatsController < ApplicationController
# GET /mats/1
# GET /mats/1.json
def show
@match = @mat.unfinished_matches.first
bout_number_param = params[:bout_number] # Read the bout_number from the URL params
if bout_number_param
@show_next_bout_button = false
@match = @mat.unfinished_matches.find { |m| m.bout_number == bout_number_param.to_i }
else
@show_next_bout_button = true
@match = @mat.unfinished_matches.first
end
@next_match = @mat.unfinished_matches.second # Second unfinished match on the mat
@wrestlers = []
if @match
if @match.w1
@@ -19,6 +30,7 @@ class MatsController < ApplicationController
@wrestler1_school_name = "N/A"
@wrestler1_last_match = nil
end
if @match.w2
@wrestler2_name = @match.wrestler2.name
@wrestler2_school_name = @match.wrestler2.school.name
@@ -29,11 +41,13 @@ class MatsController < ApplicationController
@wrestler2_school_name = "N/A"
@wrestler2_last_match = nil
end
@tournament = @match.tournament
end
session[:return_path] = request.original_fullpath
session[:error_return_path] = request.original_fullpath
end
end
# GET /mats/new
def new