diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 3869ef6..4cca8ed 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -27,7 +27,7 @@ class MatchesController < ApplicationController def update respond_to do |format| 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 } else 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. 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 def check_access diff --git a/app/models/match.rb b/app/models/match.rb index 0051fc3..fd735cf 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -5,6 +5,7 @@ class Match < ActiveRecord::Base has_many :wrestlers, :through => :weight after_update :after_finished_actions, :if => :saved_change_to_finished? after_update :after_finished_actions, :if => :saved_change_to_winner_id? + attr_accessor :redirect_path def after_finished_actions if self.finished == 1 && self.winner_id != nil diff --git a/app/views/matches/_form.html.erb b/app/views/matches/_form.html.erb index 4b183c0..313744e 100644 --- a/app/views/matches/_form.html.erb +++ b/app/views/matches/_form.html.erb @@ -88,7 +88,8 @@
<%= 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 %>
diff --git a/app/views/matches/edit.html.erb b/app/views/matches/edit.html.erb index 4540c95..01900a0 100644 --- a/app/views/matches/edit.html.erb +++ b/app/views/matches/edit.html.erb @@ -1,6 +1,3 @@ -<%= link_to "Back to #{@match.tournament.name} matches", "/tournaments/#{@match.tournament.id}/matches", :class=>"btn btn-default" %> -
-

<%= @w1.name %> VS. <%= @w2.name %>

- +<% @redirect_path = "/tournaments/#{@tournament.id}/matches" %> <%= render 'form' %> diff --git a/app/views/mats/show.html.erb b/app/views/mats/show.html.erb index 566ce7f..54fbf31 100644 --- a/app/views/mats/show.html.erb +++ b/app/views/mats/show.html.erb @@ -1,8 +1,3 @@ - -<%= link_to "Back to #{@mat.tournament.name}", "/tournaments/#{@mat.tournament.id}", :class=>"btn btn-default" %> -
-
-

Mat <%= @mat.name %>

@@ -10,11 +5,9 @@ Tournament: <%= @mat.tournament.name %>

- -
-
+<% @redirect_path = request.original_fullpath %> <% if @match %> -<%= render 'match_edit_form' %> +<%= render 'matches/form' %> <% else %>

No matches assigned to this mat.

<% end %>