1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-05-07 14:52:39 +00:00

Redirect errors on match#stat back to match#stat

This commit is contained in:
2023-01-09 19:27:31 -05:00
parent eb56b9d16c
commit 371b44977f
2 changed files with 9 additions and 2 deletions

View File

@@ -50,6 +50,7 @@ class MatchesController < ApplicationController
@tournament = @match.tournament @tournament = @match.tournament
end end
session[:return_path] = "/tournaments/#{@tournament.id}/matches" session[:return_path] = "/tournaments/#{@tournament.id}/matches"
session[:error_return_path] = "/matches/#{@match.id}/stat"
end end
@@ -65,8 +66,13 @@ class MatchesController < ApplicationController
end end
format.json { head :no_content } format.json { head :no_content }
else else
format.html { redirect_to session.delete(:return_path), alert: "Match did not save because: #{@match.errors.full_messages.to_s}" } if session[:error_return_path]
format.json { render json: @match.errors, status: :unprocessable_entity } format.html { redirect_to session.delete(:error_return_path), alert: "Match did not save because: #{@match.errors.full_messages.to_s}" }
format.json { render json: @match.errors, status: :unprocessable_entity }
else
format.html { redirect_to "/tournaments/#{@match.tournament.id}", alert: "Match did not save because: #{@match.errors.full_messages.to_s}" }
format.json { render json: @match.errors, status: :unprocessable_entity }
end
end end
end end
end end

View File

@@ -32,6 +32,7 @@ class MatsController < ApplicationController
@tournament = @match.tournament @tournament = @match.tournament
end end
session[:return_path] = request.original_fullpath session[:return_path] = request.original_fullpath
session[:error_return_path] = request.original_fullpath
end end
# GET /mats/new # GET /mats/new