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

Matche edit and mat show redirect properly

This commit is contained in:
2019-01-23 16:04:51 +00:00
parent 100317075b
commit 19f10ec80b
5 changed files with 8 additions and 16 deletions

View File

@@ -27,7 +27,7 @@ class MatchesController < ApplicationController
def update def update
respond_to do |format| respond_to do |format|
if @match.update(match_params) if @match.update(match_params)
format.html { redirect_to mat_path(@match.mat_id), notice: 'Match was successfully updated.' } format.html { redirect_to params[:match][:redirect_path], notice: 'Match was successfully updated.' }
format.json { head :no_content } format.json { head :no_content }
else else
format.html { render action: 'edit' } format.html { render action: 'edit' }
@@ -45,7 +45,7 @@ class MatchesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def match_params def match_params
params.require(:match).permit(:w1, :w2, :w1_stat, :w2_stat, :winner_id, :win_type, :score, :finished) params.require(:match).permit(:w1, :w2, :w1_stat, :w2_stat, :winner_id, :win_type, :score, :finished, :redirect_path)
end end
def check_access def check_access

View File

@@ -5,6 +5,7 @@ class Match < ActiveRecord::Base
has_many :wrestlers, :through => :weight has_many :wrestlers, :through => :weight
after_update :after_finished_actions, :if => :saved_change_to_finished? after_update :after_finished_actions, :if => :saved_change_to_finished?
after_update :after_finished_actions, :if => :saved_change_to_winner_id? after_update :after_finished_actions, :if => :saved_change_to_winner_id?
attr_accessor :redirect_path
def after_finished_actions def after_finished_actions
if self.finished == 1 && self.winner_id != nil if self.finished == 1 && self.winner_id != nil

View File

@@ -88,7 +88,8 @@
<br> <br>
<%= f.hidden_field :finished, :value => 1 %> <%= f.hidden_field :finished, :value => 1 %>
<%= f.hidden_field :round, :value => @match.round %> <%= f.hidden_field :round, :value => @match.round %>
<%= f.hidden_field :redirect_path, :value => @redirect_path %>
<br> <br>

View File

@@ -1,6 +1,3 @@
<%= link_to "Back to #{@match.tournament.name} matches", "/tournaments/#{@match.tournament.id}/matches", :class=>"btn btn-default" %>
<br>
<br>
<h1><%= @w1.name %> VS. <%= @w2.name %></h1> <h1><%= @w1.name %> VS. <%= @w2.name %></h1>
<% @redirect_path = "/tournaments/#{@tournament.id}/matches" %>
<%= render 'form' %> <%= render 'form' %>

View File

@@ -1,8 +1,3 @@
<%= link_to "Back to #{@mat.tournament.name}", "/tournaments/#{@mat.tournament.id}", :class=>"btn btn-default" %>
<br>
<br>
<p>
<strong>Mat <%= @mat.name %></strong> <strong>Mat <%= @mat.name %></strong>
</p> </p>
@@ -10,11 +5,9 @@
<strong>Tournament:</strong> <strong>Tournament:</strong>
<%= @mat.tournament.name %> <%= @mat.tournament.name %>
</p> </p>
<% @redirect_path = request.original_fullpath %>
<br>
<br>
<% if @match %> <% if @match %>
<%= render 'match_edit_form' %> <%= render 'matches/form' %>
<% else %> <% else %>
<p>No matches assigned to this mat.</p> <p>No matches assigned to this mat.</p>
<% end %> <% end %>