mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-05 06:07:20 +00:00
Fixed redirect for match editing and added controller tests. Added wrestler school name to match edit form. Added authorization tests to all matches page.
This commit is contained in:
@@ -19,6 +19,7 @@ class MatchesController < ApplicationController
|
||||
@wrestlers = [@w1,@w2]
|
||||
@tournament = @match.tournament
|
||||
end
|
||||
session[:return_path] = "/tournaments/#{@tournament.id}/matches"
|
||||
end
|
||||
|
||||
|
||||
@@ -27,8 +28,8 @@ class MatchesController < ApplicationController
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @match.update(match_params)
|
||||
if params[:match][:redirect_path]
|
||||
format.html { redirect_to params[:match][:redirect_path], notice: 'Match was successfully updated.' }
|
||||
if session[:return_path]
|
||||
format.html { redirect_to session.delete(:return_path), notice: 'Match was successfully updated.' }
|
||||
else
|
||||
format.html { redirect_to "/tournaments/#{@match.tournament.id}", notice: 'Match was successfully updated.' }
|
||||
end
|
||||
@@ -49,7 +50,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, :redirect_path)
|
||||
params.require(:match).permit(:w1, :w2, :w1_stat, :w2_stat, :winner_id, :win_type, :score, :finished)
|
||||
end
|
||||
|
||||
def check_access
|
||||
|
||||
@@ -12,6 +12,7 @@ class MatsController < ApplicationController
|
||||
@w2 = @match.wrestler2
|
||||
@wrestlers = [@w1,@w2]
|
||||
end
|
||||
session[:return_path] = request.original_fullpath
|
||||
end
|
||||
|
||||
# GET /mats/new
|
||||
|
||||
@@ -5,7 +5,6 @@ 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
|
||||
|
||||
@@ -14,14 +14,18 @@
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= @w1.name %> <select id="w1-color" onchange="changeW1Color(this)">
|
||||
<th>Name: <%= @w1.name %> <select id="w1-color" onchange="changeW1Color(this)">
|
||||
<option value="green">Green</option>
|
||||
<option value="red">Red</option>
|
||||
</select><br>Last Match: <%= if @w1.last_match != nil then time_ago_in_words(@w1.last_match.updated_at) end%></th>
|
||||
<th><%= @w2.name %> <select id="w2-color" onchange="changeW2Color(this)">
|
||||
</select>
|
||||
<br>School: <%= @w1.school.name %>
|
||||
<br>Last Match: <%= if @w1.last_match != nil then time_ago_in_words(@w2.last_match.updated_at) else "N/A" end%></th>
|
||||
<th>Name: <%= @w2.name %> <select id="w2-color" onchange="changeW2Color(this)">
|
||||
<option value="red">Red</option>
|
||||
<option value="green">Green</option>
|
||||
</select><br>Last Match: <%= if @w2.last_match != nil then time_ago_in_words(@w2.last_match.updated_at) end%></th>
|
||||
</select>
|
||||
<br>School: <%= @w2.school.name %>
|
||||
<br>Last Match: <%= if @w2.last_match != nil then time_ago_in_words(@w2.last_match.updated_at) else "N/A" end%></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -89,7 +93,6 @@
|
||||
|
||||
<%= f.hidden_field :finished, :value => 1 %>
|
||||
<%= f.hidden_field :round, :value => @match.round %>
|
||||
<%= f.hidden_field :redirect_path, :value => @redirect_path %>
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
<h1><%= @w1.name %> VS. <%= @w2.name %></h1>
|
||||
<% @redirect_path = "/tournaments/#{@tournament.id}/matches" %>
|
||||
<%= render 'form' %>
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
<strong>Mat <%= @mat.name %></strong>
|
||||
</p>
|
||||
<h3>Mat <%= @mat.name %></h3>
|
||||
<h3>Tournament: <%= @mat.tournament.name %></h3>
|
||||
|
||||
<p>
|
||||
<strong>Tournament:</strong>
|
||||
<%= @mat.tournament.name %>
|
||||
</p>
|
||||
<% @redirect_path = request.original_fullpath %>
|
||||
<% if @match %>
|
||||
<%= render 'matches/form' %>
|
||||
<% else %>
|
||||
|
||||
Reference in New Issue
Block a user