1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-05-08 23:11:00 +00:00

Fixing controllers and views with validations

This commit is contained in:
2015-12-30 19:42:58 +00:00
parent 198c6d5e82
commit 9fb1615120
8 changed files with 29 additions and 35 deletions

View File

@@ -18,14 +18,13 @@ class MatsController < ApplicationController
def new def new
@mat = Mat.new @mat = Mat.new
if params[:tournament] if params[:tournament]
@tournament_field = params[:tournament]
@tournament = Tournament.find(params[:tournament]) @tournament = Tournament.find(params[:tournament])
end end
end end
# GET /mats/1/edit # GET /mats/1/edit
def edit def edit
@tournament_field = @mat.tournament_id @tournament = Tournament.find(@mat.tournament_id)
end end
# POST /mats # POST /mats
@@ -82,17 +81,17 @@ class MatsController < ApplicationController
end end
def check_access def check_access
if params[:tournament] if params[:tournament]
@tournament = Tournament.find(params[:tournament]) @tournament = Tournament.find(params[:tournament])
elsif params[:mat] elsif params[:mat]
@mat = Mat.new(mat_params) @mat = Mat.new(mat_params)
@tournament = Tournament.find(@mat.tournament_id) @tournament = Tournament.find(@mat.tournament_id)
elsif @mat elsif @mat
@tournament = @mat.tournament @tournament = @mat.tournament
end end
if current_user != @tournament.user if current_user != @tournament.user
redirect_to '/static_pages/not_allowed' redirect_to '/static_pages/not_allowed'
end end
end end

View File

@@ -14,14 +14,12 @@ class SchoolsController < ApplicationController
def new def new
@school = School.new @school = School.new
if params[:tournament] if params[:tournament]
@tournament_field = params[:tournament]
@tournament = Tournament.find(params[:tournament]) @tournament = Tournament.find(params[:tournament])
end end
end end
# GET /schools/1/edit # GET /schools/1/edit
def edit def edit
@tournament_field = @school.tournament_id
@tournament = @school.tournament @tournament = @school.tournament
end end
@@ -79,17 +77,17 @@ class SchoolsController < ApplicationController
end end
def check_access def check_access
if params[:tournament] if params[:tournament]
@tournament = Tournament.find(params[:tournament]) @tournament = Tournament.find(params[:tournament])
elsif params[:school] elsif params[:school]
@school = School.new(school_params) @school = School.new(school_params)
@tournament = Tournament.find(@school.tournament_id) @tournament = Tournament.find(@school.tournament_id)
elsif @school elsif @school
@tournament = @school.tournament @tournament = @school.tournament
end end
if current_user != @tournament.user if current_user != @tournament.user
redirect_to '/static_pages/not_allowed' redirect_to '/static_pages/not_allowed'
end end
end end
end end

View File

@@ -18,14 +18,12 @@ class WeightsController < ApplicationController
def new def new
@weight = Weight.new @weight = Weight.new
if params[:tournament] if params[:tournament]
@tournament_field = params[:tournament]
@tournament = Tournament.find(params[:tournament]) @tournament = Tournament.find(params[:tournament])
end end
end end
# GET /weights/1/edit # GET /weights/1/edit
def edit def edit
@tournament_field = @weight.tournament_id
@tournament = @weight.tournament @tournament = @weight.tournament
@mats = @tournament.mats @mats = @tournament.mats
end end

View File

@@ -14,7 +14,6 @@ class WrestlersController < ApplicationController
def new def new
@wrestler = Wrestler.new @wrestler = Wrestler.new
if params[:school] if params[:school]
@school_field = params[:school]
@school = School.find(params[:school]) @school = School.find(params[:school])
end end
if @school if @school
@@ -28,7 +27,6 @@ class WrestlersController < ApplicationController
# GET /wrestlers/1/edit # GET /wrestlers/1/edit
def edit def edit
@school_field = @wrestler.school_id
@school = @wrestler.school @school = @wrestler.school
@tournament = @wrestler.tournament @tournament = @wrestler.tournament
@weight = @wrestler.weight @weight = @wrestler.weight
@@ -40,6 +38,7 @@ class WrestlersController < ApplicationController
def create def create
@wrestler = Wrestler.new(wrestler_params) @wrestler = Wrestler.new(wrestler_params)
@school = School.find(wrestler_params[:school_id]) @school = School.find(wrestler_params[:school_id])
@weights = @school.tournament.weights
respond_to do |format| respond_to do |format|
if @wrestler.save if @wrestler.save
format.html { redirect_to @school, notice: 'Wrestler was successfully created.' } format.html { redirect_to @school, notice: 'Wrestler was successfully created.' }

View File

@@ -16,8 +16,8 @@
<%= f.text_field :name %> <%= f.text_field :name %>
</div> </div>
<% if @tournament_field %> <% if @tournament %>
<%= f.hidden_field :tournament_id, :value => @tournament_field %> <%= f.hidden_field :tournament_id, :value => @tournament.id %>
<% end %> <% end %>
<br> <br>
<div class="actions"> <div class="actions">

View File

@@ -17,7 +17,7 @@
</div> </div>
<% if @school %> <% if @school %>
<%= f.hidden_field :tournament_id, :value => @tournament_field %> <%= f.hidden_field :tournament_id, :value => @tournament.id %>
<% end %> <% end %>
<br> <br>

View File

@@ -17,7 +17,7 @@
</div> </div>
<% if @weight %> <% if @weight %>
<%= f.hidden_field :tournament_id, :value => @tournament_field %> <%= f.hidden_field :tournament_id, :value => @tournament.id %>
<% end %> <% end %>
<br> <br>
<div class="actions"> <div class="actions">

View File

@@ -18,7 +18,7 @@
</div> </div>
<% if @school %> <% if @school %>
<%= f.hidden_field :school_id, :value => @school_field %> <%= f.hidden_field :school_id, :value => @school.id %>
<% else %> <% else %>
<div class="field"> <div class="field">
<%= f.label 'School' %><br> <%= f.label 'School' %><br>