diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index d8fcfa6..0e252ee 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -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 diff --git a/app/controllers/mats_controller.rb b/app/controllers/mats_controller.rb index 5a9ce42..afeac39 100644 --- a/app/controllers/mats_controller.rb +++ b/app/controllers/mats_controller.rb @@ -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 diff --git a/app/views/matches/_matchstats.html.erb b/app/views/matches/_matchstats.html.erb index f538542..9774c16 100644 --- a/app/views/matches/_matchstats.html.erb +++ b/app/views/matches/_matchstats.html.erb @@ -11,6 +11,9 @@ <% end %>