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

Cleaning up views and controllers

This commit is contained in:
2015-11-04 07:10:20 -05:00
parent 3695800001
commit a38c959d0c
9 changed files with 32 additions and 31 deletions

View File

@@ -11,11 +11,11 @@ class MatchesController < ApplicationController
# GET /matches/1/edit
def edit
if params[:match]
@match = Match.find (params[:match])
@match = Match.where(:id => params[:match]).includes(:wrestlers).first
end
if @match
@w1 = Wrestler.find(@match.w1)
@w2 = Wrestler.find(@match.w2)
@w1 = @match.wrestler1
@w2 = @match.wrestler2
end
end

View File

@@ -22,7 +22,7 @@ class SchoolsController < ApplicationController
# GET /schools/1/edit
def edit
@tournament_field = @school.tournament_id
@tournament = Tournament.find(@school.tournament_id)
@tournament = @school.tournament
end
# POST /schools
@@ -70,7 +70,7 @@ class SchoolsController < ApplicationController
private
# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.find(params[:id])
@school = School.where(:id => params[:id]).includes(:tournament,:wrestlers).first
end
# Never trust parameters from the scary internet, only allow the white list through.

View File

@@ -97,18 +97,20 @@ class StaticPagesController < ApplicationController
Wrestler.update(params[:wrestler].keys, params[:wrestler].values)
end
if params[:tournament]
@tournament = Tournament.find(params[:tournament])
@tournament = Tournament.where(:id => params[:tournament]).includes(:weights).first
@tournament_id = @tournament.id
@tournament_name = @tournament.name
end
if @tournament
@weights = Weight.where(tournament_id: @tournament.id)
@weights = @tournament.weights
@weights = @weights.sort_by{|x|[x.max]}
end
if params[:weight]
@weight = Weight.find(params[:weight])
@tournament_id = @weight.tournament_id
@tournament_name = Tournament.find(@tournament_id).name
@weight = Weight.where(:id => params[:weight]).includes(:tournament,:wrestlers).first
@tournament_id = @weight.tournament.id
@tournament_name = @weight.tournament.name
@tournament = @weight.tournament
@weights = @tournament.weights
end
if @weight
@wrestlers = @weight.wrestlers

View File

@@ -71,7 +71,7 @@ class TournamentsController < ApplicationController
private
# Use callbacks to share common setup or constraints between actions.
def set_tournament
@tournament = Tournament.find(params[:id])
@tournament = Tournament.where(:id => params[:id]).includes(:schools,:weights,:mats).first
end
# Never trust parameters from the scary internet, only allow the white list through.

View File

@@ -9,8 +9,8 @@ class WeightsController < ApplicationController
if params[:wrestler]
Wrestler.update(params[:wrestler].keys, params[:wrestler].values)
end
@wrestlers = Wrestler.all
@tournament = Tournament.find(@weight.tournament_id)
@wrestlers = @weight.wrestlers
@tournament = @weight.tournament
end
@@ -26,8 +26,8 @@ class WeightsController < ApplicationController
# GET /weights/1/edit
def edit
@tournament_field = @weight.tournament_id
@mats = Mat.where(tournament_id: @weight.tournament.id)
@tournament = Tournament.find(@weight.tournament_id)
@tournament = @weight.tournament
@mats = @tournament.mats
end
# POST /weights
@@ -52,7 +52,7 @@ class WeightsController < ApplicationController
# PATCH/PUT /weights/1
# PATCH/PUT /weights/1.json
def update
@tournament = Tournament.find(@weight.tournament_id)
@tournament = @weight.tournament
if current_user != @tournament.user
redirect_to root_path
end
@@ -84,7 +84,7 @@ class WeightsController < ApplicationController
private
# Use callbacks to share common setup or constraints between actions.
def set_weight
@weight = Weight.find(params[:id])
@weight = Weight.where(:id => params[:id]).includes(:tournament,:wrestlers).first
end
# Never trust parameters from the scary internet, only allow the white list through.

View File

@@ -6,7 +6,7 @@ class WrestlersController < ApplicationController
# GET /wrestlers/1
# GET /wrestlers/1.json
def show
@school = School.find(@wrestler.school_id)
@school = @wrestler.school
end
# GET /wrestlers/new
@@ -20,9 +20,7 @@ class WrestlersController < ApplicationController
@tournament = Tournament.find(@school.tournament_id)
end
if @tournament
@weight = Weight.where(tournament_id: @tournament.id)
else
@weight = Weight.all
@weights = Weight.where(tournament_id: @tournament.id)
end
end
@@ -30,9 +28,10 @@ class WrestlersController < ApplicationController
# GET /wrestlers/1/edit
def edit
@school_field = @wrestler.school_id
@school = School.find(@wrestler.school_id)
@tournament = Tournament.find(@school.tournament_id)
@weight = Weight.where(tournament_id: @tournament.id)
@school = @wrestler.school
@tournament = @wrestler.tournament
@weight = @wrestler.weight
@weights = @tournament.weights
end
# POST /wrestlers
@@ -54,7 +53,7 @@ class WrestlersController < ApplicationController
# PATCH/PUT /wrestlers/1
# PATCH/PUT /wrestlers/1.json
def update
@school = School.find(@wrestler.school_id)
@school = @wrestler.school
respond_to do |format|
if @wrestler.update(wrestler_params)
format.html { redirect_to @school, notice: 'Wrestler was successfully updated.' }
@@ -69,7 +68,7 @@ class WrestlersController < ApplicationController
# DELETE /wrestlers/1
# DELETE /wrestlers/1.json
def destroy
@school = School.find(@wrestler.school_id)
@school = @wrestler.school
@wrestler.destroy
respond_to do |format|
format.html { redirect_to @school }
@@ -80,7 +79,7 @@ class WrestlersController < ApplicationController
private
# Use callbacks to share common setup or constraints between actions.
def set_wrestler
@wrestler = Wrestler.find(params[:id])
@wrestler = Wrestler.where(:id => params[:id]).includes(:tournament,:school,:weight).first
end
# Never trust parameters from the scary internet, only allow the white list through.

View File

@@ -1,7 +1,7 @@
<%= link_to "Back to #{@tournament_name}", "/tournaments/#{@tournament_id}", :class=>"btn btn-default" %>
<br>
<br>
<% if @tournament %>
<% if params[:tournament] %>
<% @weights.each do |weight| %>
<%= link_to "#{weight.max}" , "/static_pages/weigh_in?weight=#{weight.id}" %>
<br>

View File

@@ -21,12 +21,12 @@
<% else %>
<div class="field">
<%= f.label 'School' %><br>
<%= f.collection_select :school_id, School.all, :id, :name %>
<%= f.collection_select :school_id, @tournament.schools, :id, :name %>
</div>
<% end %>
<div class="field">
<%= f.label 'Weight Class' %><br>
<%= f.collection_select :weight_id, @weight, :id, :max %>
<%= f.collection_select :weight_id, @weights, :id, :max %>
</div>
<div class="field">

View File

@@ -15,7 +15,7 @@ class WrestlersControllerTest < ActionController::TestCase
end
def new
get :new, school: @wrestler.school.id
get :new, school: 1
end
def post_update