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 # GET /matches/1/edit
def edit def edit
if params[:match] if params[:match]
@match = Match.find (params[:match]) @match = Match.where(:id => params[:match]).includes(:wrestlers).first
end end
if @match if @match
@w1 = Wrestler.find(@match.w1) @w1 = @match.wrestler1
@w2 = Wrestler.find(@match.w2) @w2 = @match.wrestler2
end end
end end

View File

@@ -22,7 +22,7 @@ class SchoolsController < ApplicationController
# GET /schools/1/edit # GET /schools/1/edit
def edit def edit
@tournament_field = @school.tournament_id @tournament_field = @school.tournament_id
@tournament = Tournament.find(@school.tournament_id) @tournament = @school.tournament
end end
# POST /schools # POST /schools
@@ -70,7 +70,7 @@ class SchoolsController < ApplicationController
private private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.
def set_school def set_school
@school = School.find(params[:id]) @school = School.where(:id => params[:id]).includes(:tournament,:wrestlers).first
end end
# 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.

View File

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

View File

@@ -71,7 +71,7 @@ class TournamentsController < ApplicationController
private private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.
def set_tournament def set_tournament
@tournament = Tournament.find(params[:id]) @tournament = Tournament.where(:id => params[:id]).includes(:schools,:weights,:mats).first
end end
# 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.

View File

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

View File

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

View File

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

View File

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

View File

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