1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-05-04 04:55:17 +00:00

Updated re-directs, added weights to tournament#show, and edited a few views

This commit is contained in:
Jacob Cody Wimer
2014-01-22 13:12:40 -05:00
parent 4a463132da
commit d4b97c83c3
13 changed files with 91 additions and 20 deletions

View File

@@ -25,16 +25,17 @@ class SchoolsController < ApplicationController
# GET /schools/1/edit # GET /schools/1/edit
def edit def edit
@tournament_field = @school.tournament_id
end end
# POST /schools # POST /schools
# POST /schools.json # POST /schools.json
def create def create
@school = School.new(school_params) @school = School.new(school_params)
@tournament = Tournament.find(school_params[:tournament_id])
respond_to do |format| respond_to do |format|
if @school.save if @school.save
format.html { redirect_to @school, notice: 'School was successfully created.' } format.html { redirect_to @tournament, notice: 'School was successfully created.' }
format.json { render action: 'show', status: :created, location: @school } format.json { render action: 'show', status: :created, location: @school }
else else
format.html { render action: 'new' } format.html { render action: 'new' }
@@ -46,9 +47,10 @@ class SchoolsController < ApplicationController
# PATCH/PUT /schools/1 # PATCH/PUT /schools/1
# PATCH/PUT /schools/1.json # PATCH/PUT /schools/1.json
def update def update
@tournament = Tournament.find(@school.tournament_id)
respond_to do |format| respond_to do |format|
if @school.update(school_params) if @school.update(school_params)
format.html { redirect_to @school, notice: 'School was successfully updated.' } format.html { redirect_to @tournament, notice: 'School was successfully updated.' }
format.json { head :no_content } format.json { head :no_content }
else else
format.html { render action: 'edit' } format.html { render action: 'edit' }
@@ -60,9 +62,10 @@ class SchoolsController < ApplicationController
# DELETE /schools/1 # DELETE /schools/1
# DELETE /schools/1.json # DELETE /schools/1.json
def destroy def destroy
@tournament = Tournament.find(@school.tournament_id)
@school.destroy @school.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to schools_url } format.html { redirect_to @tournament }
format.json { head :no_content } format.json { head :no_content }
end end
end end

View File

@@ -11,6 +11,7 @@ class TournamentsController < ApplicationController
# GET /tournaments/1.json # GET /tournaments/1.json
def show def show
@schools = @tournament.schools @schools = @tournament.schools
@weights = @tournament.weights
end end
# GET /tournaments/new # GET /tournaments/new
@@ -26,7 +27,6 @@ class TournamentsController < ApplicationController
# POST /tournaments.json # POST /tournaments.json
def create def create
@tournament = Tournament.new(tournament_params) @tournament = Tournament.new(tournament_params)
respond_to do |format| respond_to do |format|
if @tournament.save if @tournament.save
format.html { redirect_to @tournament, notice: 'Tournament was successfully created.' } format.html { redirect_to @tournament, notice: 'Tournament was successfully created.' }

View File

@@ -11,25 +11,31 @@ class WeightsController < ApplicationController
# GET /weights/1.json # GET /weights/1.json
def show def show
@wrestler = Wrestler.all @wrestler = Wrestler.all
@tournament = Tournament.find(@weight.tournament_id)
end end
# GET /weights/new # GET /weights/new
def new def new
@weight = Weight.new @weight = Weight.new
if params[:tournament]
@tournament_field = params[:tournament]
@tournament = Tournament.find(params[:tournament])
end
end end
# GET /weights/1/edit # GET /weights/1/edit
def edit def edit
@tournament_field = @weight.tournament_id
end end
# POST /weights # POST /weights
# POST /weights.json # POST /weights.json
def create def create
@weight = Weight.new(weight_params) @weight = Weight.new(weight_params)
@tournament = Tournament.find(weight_params[:tournament_id])
respond_to do |format| respond_to do |format|
if @weight.save if @weight.save
format.html { redirect_to @weight, notice: 'Weight was successfully created.' } format.html { redirect_to @tournament, notice: 'Weight was successfully created.' }
format.json { render action: 'show', status: :created, location: @weight } format.json { render action: 'show', status: :created, location: @weight }
else else
format.html { render action: 'new' } format.html { render action: 'new' }
@@ -41,9 +47,10 @@ 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)
respond_to do |format| respond_to do |format|
if @weight.update(weight_params) if @weight.update(weight_params)
format.html { redirect_to @weight, notice: 'Weight was successfully updated.' } format.html { redirect_to @tournament, notice: 'Weight was successfully updated.' }
format.json { head :no_content } format.json { head :no_content }
else else
format.html { render action: 'edit' } format.html { render action: 'edit' }
@@ -55,9 +62,10 @@ class WeightsController < ApplicationController
# DELETE /weights/1 # DELETE /weights/1
# DELETE /weights/1.json # DELETE /weights/1.json
def destroy def destroy
@tournament = Tournament.find(@weight.tournament_id)
@weight.destroy @weight.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to weights_url } format.html { redirect_to @tournament }
format.json { head :no_content } format.json { head :no_content }
end end
end end
@@ -70,6 +78,6 @@ class WeightsController < ApplicationController
# 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.
def weight_params def weight_params
params.require(:weight).permit(:max) params.require(:weight).permit(:max, :tournament_id)
end end
end end

View File

@@ -5,6 +5,7 @@ class WrestlersController < ApplicationController
# GET /wrestlers.json # GET /wrestlers.json
def index def index
@wrestlers = Wrestler.all @wrestlers = Wrestler.all
#@school = School.find(@wrestler.school_id)
end end
# GET /wrestlers/1 # GET /wrestlers/1
@@ -19,20 +20,30 @@ class WrestlersController < ApplicationController
@school_field = params[:school] @school_field = params[:school]
@school = School.find(params[:school]) @school = School.find(params[:school])
end end
if @school
@tournament = Tournament.find(@school.tournament_id)
end
if @tournament
@weight = Weight.where(tournament_id: @tournament.id)
else
@weight = Weight.all
end
end end
# GET /wrestlers/1/edit # GET /wrestlers/1/edit
def edit def edit
@school_field = @wrestler.school_id
end end
# POST /wrestlers # POST /wrestlers
# POST /wrestlers.json # POST /wrestlers.json
def create def create
@wrestler = Wrestler.new(wrestler_params) @wrestler = Wrestler.new(wrestler_params)
@school = School.find(wrestler_params[:school_id])
respond_to do |format| respond_to do |format|
if @wrestler.save if @wrestler.save
format.html { redirect_to @wrestler, notice: 'Wrestler was successfully created.' } format.html { redirect_to @school, notice: 'Wrestler was successfully created.' }
format.json { render action: 'show', status: :created, location: @wrestler } format.json { render action: 'show', status: :created, location: @wrestler }
else else
format.html { render action: 'new' } format.html { render action: 'new' }
@@ -44,9 +55,10 @@ 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)
respond_to do |format| respond_to do |format|
if @wrestler.update(wrestler_params) if @wrestler.update(wrestler_params)
format.html { redirect_to @wrestler, notice: 'Wrestler was successfully updated.' } format.html { redirect_to @school, notice: 'Wrestler was successfully updated.' }
format.json { head :no_content } format.json { head :no_content }
else else
format.html { render action: 'edit' } format.html { render action: 'edit' }
@@ -58,9 +70,10 @@ 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)
@wrestler.destroy @wrestler.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to wrestlers_url } format.html { redirect_to @school }
format.json { head :no_content } format.json { head :no_content }
end end
end end

View File

@@ -1,4 +1,4 @@
class School < ActiveRecord::Base class School < ActiveRecord::Base
belongs_to :tournament belongs_to :tournament
has_many :wrestlers has_many :wrestlers, dependent: :destroy
end end

View File

@@ -1,3 +1,4 @@
class Tournament < ActiveRecord::Base class Tournament < ActiveRecord::Base
has_many :schools has_many :schools, dependent: :destroy
has_many :weights, dependent: :destroy
end end

View File

@@ -1,3 +1,4 @@
class Weight < ActiveRecord::Base class Weight < ActiveRecord::Base
has_many :wrestlers belongs_to :tournament
has_many :wrestlers, dependent: :destroy
end end

View File

@@ -54,6 +54,36 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<br>
<br>
<% if user_signed_in? %>
<%= link_to "New #{@tournament.name} Weight" , "/weights/new?tournament=#{@tournament.id}" %>
<% end %>
<br>
<br>
<h3>Weights</h3>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Weight Class</th>
<th></th>
</tr>
</thead>
<tbody>
<% @weights.each do |weight| %>
<tr>
<td><%= weight.max %></td>
<td><%= link_to 'Show', weight, :class=>"btn" %>
<% if user_signed_in? %>
<%= link_to 'Edit', edit_weight_path(weight), :class=>"btn" %>
<%= link_to 'Destroy', weight, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -15,6 +15,16 @@
<%= f.label :max %><br> <%= f.label :max %><br>
<%= f.number_field :max %> <%= f.number_field :max %>
</div> </div>
<% if @weight %>
<%= f.hidden_field :tournament_id, :value => @tournament_field %>
<% else %>
<div class="field">
<%= f.label 'Tournament' %><br>
<%= f.collection_select :tournament_id, Tournament.all, :id, :name %>
</div>
<% end %>
<div class="actions"> <div class="actions">
<%= f.submit %> <%= f.submit %>
</div> </div>

View File

@@ -5,7 +5,6 @@
<%= link_to "Edit #{@weight.max} Weight Class", edit_weight_path(@weight) %> | <%= link_to "Edit #{@weight.max} Weight Class", edit_weight_path(@weight) %> |
<%= link_to 'Back to Weight Classes', weights_path %> | <%= link_to 'Back to Weight Classes', weights_path %> |
<%= link_to 'Back to Admin', '/admin/index' %>
<br> <br>
<br> <br>
<br> <br>

View File

@@ -27,7 +27,7 @@
<div class="field"> <div class="field">
<%= f.label 'Weight Class' %><br> <%= f.label 'Weight Class' %><br>
<%= f.collection_select :weight_id, Weight.all, :id, :max %> <%= f.collection_select :weight_id, @weight, :id, :max %>
</div> </div>
<div class="field"> <div class="field">
<%= f.label :original_seed %><br> <%= f.label :original_seed %><br>

View File

@@ -0,0 +1,5 @@
class WeightAddTournamentId < ActiveRecord::Migration
def change
add_column :weights, :tournament_id, :integer
end
end

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140122030856) do ActiveRecord::Schema.define(version: 20140122151620) do
create_table "schools", force: true do |t| create_table "schools", force: true do |t|
t.string "name" t.string "name"
@@ -52,6 +52,7 @@ ActiveRecord::Schema.define(version: 20140122030856) do
t.integer "max" t.integer "max"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "tournament_id"
end end
create_table "wrestlers", force: true do |t| create_table "wrestlers", force: true do |t|