mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-21 22:24:29 +00:00
Auto creating of high school weights
This commit is contained in:
@@ -67,6 +67,19 @@ class StaticPagesController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def createCustomWeights
|
||||||
|
if user_signed_in?
|
||||||
|
else
|
||||||
|
redirect_to root_path
|
||||||
|
end
|
||||||
|
@tournament = Tournament.find(params[:tournament])
|
||||||
|
@custom = params[:customValue].to_s
|
||||||
|
@tournament.createCustomWeights(@custom)
|
||||||
|
|
||||||
|
redirect_to "/tournaments/#{@tournament.id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def noMatches
|
def noMatches
|
||||||
if params[:tournament]
|
if params[:tournament]
|
||||||
@tournament = Tournament.find(params[:tournament])
|
@tournament = Tournament.find(params[:tournament])
|
||||||
|
|||||||
@@ -61,6 +61,14 @@ class TournamentsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def createHsWeights
|
||||||
|
if params[:tournament]
|
||||||
|
if user_signed_in?
|
||||||
|
@tournament.createHsWeights
|
||||||
|
end
|
||||||
|
redirect_to "/tournaments/#{@tournament.id}"
|
||||||
|
end
|
||||||
|
end
|
||||||
# DELETE /tournaments/1
|
# DELETE /tournaments/1
|
||||||
# DELETE /tournaments/1.json
|
# DELETE /tournaments/1.json
|
||||||
def destroy
|
def destroy
|
||||||
|
|||||||
@@ -42,15 +42,16 @@ class WeightsController < ApplicationController
|
|||||||
end
|
end
|
||||||
@weight = Weight.new(weight_params)
|
@weight = Weight.new(weight_params)
|
||||||
@tournament = Tournament.find(weight_params[:tournament_id])
|
@tournament = Tournament.find(weight_params[:tournament_id])
|
||||||
respond_to do |format|
|
|
||||||
if @weight.save
|
respond_to do |format|
|
||||||
format.html { redirect_to @tournament, notice: 'Weight was successfully created.' }
|
if @weight.save
|
||||||
format.json { render action: 'show', status: :created, location: @weight }
|
format.html { redirect_to @tournament, notice: 'Weight was successfully created.' }
|
||||||
else
|
format.json { render action: 'show', status: :created, location: @weight }
|
||||||
format.html { render action: 'new' }
|
else
|
||||||
format.json { render json: @weight.errors, status: :unprocessable_entity }
|
format.html { render action: 'new' }
|
||||||
|
format.json { render json: @weight.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# PATCH/PUT /weights/1
|
# PATCH/PUT /weights/1
|
||||||
|
|||||||
@@ -13,7 +13,18 @@ class Tournament < ActiveRecord::Base
|
|||||||
@matches = Match.where(tournament_id: self.id)
|
@matches = Match.where(tournament_id: self.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def createCustomWeights(value)
|
||||||
|
self.weights.destroy_all
|
||||||
|
if value == 'hs'
|
||||||
|
@weights = [106,113,120,132,138,145,152,160,170,182,195,220,285]
|
||||||
|
end
|
||||||
|
@weights.each do |w|
|
||||||
|
newWeight = Weight.new
|
||||||
|
newWeight.max = w
|
||||||
|
newWeight.tournament_id = self.id
|
||||||
|
newWeight.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def upcomingMatches
|
def upcomingMatches
|
||||||
if matches.nil?
|
if matches.nil?
|
||||||
|
|||||||
@@ -55,12 +55,14 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<% if user_signed_in? %>
|
<% if user_signed_in? %>
|
||||||
<%= link_to "New #{@tournament.name} Weight" , "/weights/new?tournament=#{@tournament.id}" %>
|
<%= link_to "New #{@tournament.name} Weight" , "/weights/new?tournament=#{@tournament.id}" %>
|
||||||
|
<br>
|
||||||
|
<%= link_to "Create HS Weights" , "/static_pages/createCustomWeights?tournament=#{@tournament.id}&customValue=hs" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ Wrestling::Application.routes.draw do
|
|||||||
get 'static_pages/results'
|
get 'static_pages/results'
|
||||||
get 'static_pages/team_scores'
|
get 'static_pages/team_scores'
|
||||||
get 'static_pages/noMatches'
|
get 'static_pages/noMatches'
|
||||||
|
get 'static_pages/createCustomWeights'
|
||||||
|
|
||||||
# Example of regular route:
|
# Example of regular route:
|
||||||
# get 'products/:id' => 'catalog#view'
|
# get 'products/:id' => 'catalog#view'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user