1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-01 20:25:26 +00:00

Added basic scaffolds for schools wrestlers and weights

This commit is contained in:
Jacob Cody Wimer
2013-12-31 11:23:43 -05:00
parent 5b6a127549
commit 24d9deee8b
57 changed files with 943 additions and 1 deletions

View File

@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@@ -0,0 +1,69 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}
a {
color: #000;
&:visited {
color: #666;
}
&:hover {
color: #fff;
background-color: #000;
}
}
div {
&.field, &.actions {
margin-bottom: 10px;
}
}
#notice {
color: green;
}
.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}
#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff;
}
ul li {
font-size: 12px;
list-style: square;
}
}

View File

@@ -0,0 +1,3 @@
// Place all the styles related to the Schools controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@@ -0,0 +1,3 @@
// Place all the styles related to the Weights controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@@ -0,0 +1,3 @@
// Place all the styles related to the Wrestlers controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@@ -0,0 +1,74 @@
class SchoolsController < ApplicationController
before_action :set_school, only: [:show, :edit, :update, :destroy]
# GET /schools
# GET /schools.json
def index
@schools = School.all
end
# GET /schools/1
# GET /schools/1.json
def show
end
# GET /schools/new
def new
@school = School.new
end
# GET /schools/1/edit
def edit
end
# POST /schools
# POST /schools.json
def create
@school = School.new(school_params)
respond_to do |format|
if @school.save
format.html { redirect_to @school, notice: 'School was successfully created.' }
format.json { render action: 'show', status: :created, location: @school }
else
format.html { render action: 'new' }
format.json { render json: @school.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /schools/1
# PATCH/PUT /schools/1.json
def update
respond_to do |format|
if @school.update(school_params)
format.html { redirect_to @school, notice: 'School was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @school.errors, status: :unprocessable_entity }
end
end
end
# DELETE /schools/1
# DELETE /schools/1.json
def destroy
@school.destroy
respond_to do |format|
format.html { redirect_to schools_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def school_params
params.require(:school).permit(:name, :score)
end
end

View File

@@ -2,5 +2,9 @@ class StaticPagesController < ApplicationController
def index
end
def school
@school = School.all
end
end

View File

@@ -0,0 +1,75 @@
class WeightsController < ApplicationController
before_action :set_weight, only: [:show, :edit, :update, :destroy]
# GET /weights
# GET /weights.json
def index
@weights = Weight.all
end
# GET /weights/1
# GET /weights/1.json
def show
@wrestler = Wrestler.all
end
# GET /weights/new
def new
@weight = Weight.new
end
# GET /weights/1/edit
def edit
end
# POST /weights
# POST /weights.json
def create
@weight = Weight.new(weight_params)
respond_to do |format|
if @weight.save
format.html { redirect_to @weight, notice: 'Weight was successfully created.' }
format.json { render action: 'show', status: :created, location: @weight }
else
format.html { render action: 'new' }
format.json { render json: @weight.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /weights/1
# PATCH/PUT /weights/1.json
def update
respond_to do |format|
if @weight.update(weight_params)
format.html { redirect_to @weight, notice: 'Weight was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @weight.errors, status: :unprocessable_entity }
end
end
end
# DELETE /weights/1
# DELETE /weights/1.json
def destroy
@weight.destroy
respond_to do |format|
format.html { redirect_to weights_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_weight
@weight = Weight.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def weight_params
params.require(:weight).permit(:max)
end
end

View File

@@ -0,0 +1,74 @@
class WrestlersController < ApplicationController
before_action :set_wrestler, only: [:show, :edit, :update, :destroy]
# GET /wrestlers
# GET /wrestlers.json
def index
@wrestlers = Wrestler.all
end
# GET /wrestlers/1
# GET /wrestlers/1.json
def show
end
# GET /wrestlers/new
def new
@wrestler = Wrestler.new
end
# GET /wrestlers/1/edit
def edit
end
# POST /wrestlers
# POST /wrestlers.json
def create
@wrestler = Wrestler.new(wrestler_params)
respond_to do |format|
if @wrestler.save
format.html { redirect_to @wrestler, notice: 'Wrestler was successfully created.' }
format.json { render action: 'show', status: :created, location: @wrestler }
else
format.html { render action: 'new' }
format.json { render json: @wrestler.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /wrestlers/1
# PATCH/PUT /wrestlers/1.json
def update
respond_to do |format|
if @wrestler.update(wrestler_params)
format.html { redirect_to @wrestler, notice: 'Wrestler was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @wrestler.errors, status: :unprocessable_entity }
end
end
end
# DELETE /wrestlers/1
# DELETE /wrestlers/1.json
def destroy
@wrestler.destroy
respond_to do |format|
format.html { redirect_to wrestlers_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_wrestler
@wrestler = Wrestler.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def wrestler_params
params.require(:wrestler).permit(:name, :school_id, :weight_id, :seed, :original_seed)
end
end

View File

@@ -0,0 +1,2 @@
module SchoolsHelper
end

View File

@@ -0,0 +1,2 @@
module WeightsHelper
end

View File

@@ -0,0 +1,2 @@
module WrestlersHelper
end

3
app/models/school.rb Normal file
View File

@@ -0,0 +1,3 @@
class School < ActiveRecord::Base
has_many :wrestlers
end

3
app/models/weight.rb Normal file
View File

@@ -0,0 +1,3 @@
class Weight < ActiveRecord::Base
has_many :wrestlers
end

4
app/models/wrestler.rb Normal file
View File

@@ -0,0 +1,4 @@
class Wrestler < ActiveRecord::Base
belongs_to :school
belongs_to :weight
end

View File

@@ -5,7 +5,9 @@
<nav>
<ul class="nav pull-right">
<li><%= link_to "Home", root_path %></li>
<li><%= link_to "Help", '#' %></li>
<li><%= link_to "School Scores", '/static_pages/school' %></li>
<li><%= link_to "Brackets" , '#' %></li>
<li><%= link_to "Bout Board" , '#' %></li>
</ul>
</nav>
</div>

View File

@@ -0,0 +1,25 @@
<%= form_for(@school) do |f| %>
<% if @school.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@school.errors.count, "error") %> prohibited this school from being saved:</h2>
<ul>
<% @school.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :score %><br>
<%= f.number_field :score %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@@ -0,0 +1,6 @@
<h1>Editing school</h1>
<%= render 'form' %>
<%= link_to 'Show', @school %> |
<%= link_to 'Back', schools_path %>

View File

@@ -0,0 +1,29 @@
<h1>Listing schools</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Score</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @schools.each do |school| %>
<tr>
<td><%= school.name %></td>
<td><%= school.score %></td>
<td><%= link_to 'Show', school %></td>
<td><%= link_to 'Edit', edit_school_path(school) %></td>
<td><%= link_to 'Destroy', school, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New School', new_school_path %>

View File

@@ -0,0 +1,4 @@
json.array!(@schools) do |school|
json.extract! school, :id, :name, :score
json.url school_url(school, format: :json)
end

View File

@@ -0,0 +1,5 @@
<h1>New school</h1>
<%= render 'form' %>
<%= link_to 'Back', schools_path %>

View File

@@ -0,0 +1,14 @@
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= @school.name %>
</p>
<p>
<strong>Score:</strong>
<%= @school.score %>
</p>
<%= link_to 'Edit', edit_school_path(@school) %> |
<%= link_to 'Back', schools_path %>

View File

@@ -0,0 +1 @@
json.extract! @school, :id, :name, :score, :created_at, :updated_at

View File

@@ -0,0 +1,17 @@
<h1>School Scores</h1>
<table class="table table-striped table-bordered">
<thead>
<tr>
<td>Name</td>
<td>Score</td>
</tr>
</thead>
<tbody>
<% @school.each do |school| %>
<tr>
<td><%= school.name %></td>
<td><%= school.score %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,21 @@
<%= form_for(@weight) do |f| %>
<% if @weight.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@weight.errors.count, "error") %> prohibited this weight from being saved:</h2>
<ul>
<% @weight.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :max %><br>
<%= f.number_field :max %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@@ -0,0 +1,6 @@
<h1>Editing weight</h1>
<%= render 'form' %>
<%= link_to 'Show', @weight %> |
<%= link_to 'Back', weights_path %>

View File

@@ -0,0 +1,27 @@
<h1>Listing weights</h1>
<table>
<thead>
<tr>
<th>Max</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @weights.each do |weight| %>
<tr>
<td><%= weight.max %></td>
<td><%= link_to 'Show', weight %></td>
<td><%= link_to 'Edit', edit_weight_path(weight) %></td>
<td><%= link_to 'Destroy', weight, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Weight', new_weight_path %>

View File

@@ -0,0 +1,4 @@
json.array!(@weights) do |weight|
json.extract! weight, :id, :max
json.url weight_url(weight, format: :json)
end

View File

@@ -0,0 +1,5 @@
<h1>New weight</h1>
<%= render 'form' %>
<%= link_to 'Back', weights_path %>

View File

@@ -0,0 +1,37 @@
<p id="notice"><%= notice %></p>
<h1>Weight Class:<%= @weight.max %></h1>
<%= link_to 'Edit Weight Class', edit_weight_path(@weight) %> |
<%= link_to 'Back to Weight Classes', weights_path %>
<br>
<br>
<br>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>School</th>
<th>Seed</th>
<th>Actions for wrestler</th>
</tr>
</thead>
<tbody>
<% @wrestler.each do |wrestler| %>
<% if wrestler.weight_id == @weight.id %>
<tr>
<td><%= wrestler.name %></td>
<td><%= School.find(wrestler.school_id).name %></td>
<td><%= wrestler.original_seed %></td>
<td><%= link_to 'Show', wrestler , :class=>"btn" %><%= link_to 'Edit', edit_wrestler_path(wrestler) , :class=>"btn" %><%= link_to 'Destroy', wrestler, method: :delete, data: { confirm: 'Are you sure?' } , :class=>"btn btn-danger" %></td>
</tr>
<% end %>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1 @@
json.extract! @weight, :id, :max, :created_at, :updated_at

View File

@@ -0,0 +1,39 @@
<%= form_for(@wrestler) do |f| %>
<% if @wrestler.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@wrestler.errors.count, "error") %> prohibited this wrestler from being saved:</h2>
<ul>
<% @wrestler.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label 'School' %><br>
<%= f.collection_select :school_id, School.all, :id, :name %>
</div>
<div class="field">
<%= f.label 'Weight Class' %><br>
<%= f.collection_select :weight_id, Weight.all, :id, :max %>
</div>
<div class="field">
<%= f.label :seed %><br>
<%= f.number_field :seed %>
</div>
<div class="field">
<%= f.label :original_seed %><br>
<%= f.number_field :original_seed %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@@ -0,0 +1,6 @@
<h1>Editing wrestler</h1>
<%= render 'form' %>
<%= link_to 'Show', @wrestler %> |
<%= link_to 'Back', wrestlers_path %>

View File

@@ -0,0 +1,35 @@
<h1>Listing wrestlers</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>School</th>
<th>Weight</th>
<th>Seed</th>
<th>Original seed</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @wrestlers.each do |wrestler| %>
<tr>
<td><%= wrestler.name %></td>
<td><%= School.find(wrestler.school_id).name %></td>
<td><%= Weight.find(wrestler.weight_id).max %></td>
<td><%= wrestler.seed %></td>
<td><%= wrestler.original_seed %></td>
<td><%= link_to 'Show', wrestler %></td>
<td><%= link_to 'Edit', edit_wrestler_path(wrestler) %></td>
<td><%= link_to 'Destroy', wrestler, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Wrestler', new_wrestler_path %>

View File

@@ -0,0 +1,4 @@
json.array!(@wrestlers) do |wrestler|
json.extract! wrestler, :id, :name, :school_id, :weight_id, :seed, :original_seed
json.url wrestler_url(wrestler, format: :json)
end

View File

@@ -0,0 +1,5 @@
<h1>New wrestler</h1>
<%= render 'form' %>
<%= link_to 'Back', wrestlers_path %>

View File

@@ -0,0 +1,29 @@
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= @wrestler.name %>
</p>
<p>
<strong>School:</strong>
<%= School.find(@wrestler.school_id).name %>
</p>
<p>
<strong>Weight:</strong>
<%= Weight.find(@wrestler.weight_id).max %>
</p>
<p>
<strong>Seed:</strong>
<%= @wrestler.seed %>
</p>
<p>
<strong>Original seed:</strong>
<%= @wrestler.original_seed %>
</p>
<%= link_to 'Edit', edit_wrestler_path(@wrestler) %> |
<%= link_to 'Back', wrestlers_path %>

View File

@@ -0,0 +1 @@
json.extract! @wrestler, :id, :name, :school_id, :weight_id, :seed, :original_seed, :created_at, :updated_at