mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Added matches scaffold and ascended views of weights and schools
This commit is contained in:
3
app/assets/javascripts/matches.js.coffee
Normal file
3
app/assets/javascripts/matches.js.coffee
Normal 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/
|
||||
3
app/assets/stylesheets/matches.css.scss
Normal file
3
app/assets/stylesheets/matches.css.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the Matches controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
74
app/controllers/matches_controller.rb
Normal file
74
app/controllers/matches_controller.rb
Normal file
@@ -0,0 +1,74 @@
|
||||
class MatchesController < ApplicationController
|
||||
before_action :set_match, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /matches
|
||||
# GET /matches.json
|
||||
def index
|
||||
@matches = Match.all
|
||||
end
|
||||
|
||||
# GET /matches/1
|
||||
# GET /matches/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /matches/new
|
||||
def new
|
||||
@match = Match.new
|
||||
end
|
||||
|
||||
# GET /matches/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /matches
|
||||
# POST /matches.json
|
||||
def create
|
||||
@match = Match.new(match_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @match.save
|
||||
format.html { redirect_to @match, notice: 'Match was successfully created.' }
|
||||
format.json { render action: 'show', status: :created, location: @match }
|
||||
else
|
||||
format.html { render action: 'new' }
|
||||
format.json { render json: @match.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /matches/1
|
||||
# PATCH/PUT /matches/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @match.update(match_params)
|
||||
format.html { redirect_to @match, notice: 'Match was successfully updated.' }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: 'edit' }
|
||||
format.json { render json: @match.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /matches/1
|
||||
# DELETE /matches/1.json
|
||||
def destroy
|
||||
@match.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to matches_url }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_match
|
||||
@match = Match.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def match_params
|
||||
params.require(:match).permit(:r_id, :g_id, :g_stat, :r_stat, :winner_id, :win_type, :score)
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@ class WeightsController < ApplicationController
|
||||
# GET /weights/1
|
||||
# GET /weights/1.json
|
||||
def show
|
||||
@wrestler = Wrestler.all
|
||||
@wrestlers = Wrestler.all
|
||||
@tournament = Tournament.find(@weight.tournament_id)
|
||||
end
|
||||
|
||||
|
||||
2
app/helpers/matches_helper.rb
Normal file
2
app/helpers/matches_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module MatchesHelper
|
||||
end
|
||||
3
app/models/match.rb
Normal file
3
app/models/match.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Match < ActiveRecord::Base
|
||||
belongs_to :tournament
|
||||
end
|
||||
@@ -1,4 +1,6 @@
|
||||
class Tournament < ActiveRecord::Base
|
||||
has_many :schools, dependent: :destroy
|
||||
has_many :weights, dependent: :destroy
|
||||
has_many :matches, dependent: :destroy
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class Wrestler < ActiveRecord::Base
|
||||
belongs_to :school
|
||||
belongs_to :weight
|
||||
has_many :matches
|
||||
end
|
||||
|
||||
45
app/views/matches/_form.html.erb
Normal file
45
app/views/matches/_form.html.erb
Normal file
@@ -0,0 +1,45 @@
|
||||
<%= form_for(@match) do |f| %>
|
||||
<% if @match.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(@match.errors.count, "error") %> prohibited this match from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% @match.errors.full_messages.each do |msg| %>
|
||||
<li><%= msg %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :r_id %><br>
|
||||
<%= f.number_field :r_id %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :g_id %><br>
|
||||
<%= f.number_field :g_id %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :g_stat %><br>
|
||||
<%= f.text_area :g_stat %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :r_stat %><br>
|
||||
<%= f.text_area :r_stat %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :winner_id %><br>
|
||||
<%= f.number_field :winner_id %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :win_type %><br>
|
||||
<%= f.text_field :win_type %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :score %><br>
|
||||
<%= f.text_field :score %>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
6
app/views/matches/edit.html.erb
Normal file
6
app/views/matches/edit.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<h1>Editing match</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Show', @match %> |
|
||||
<%= link_to 'Back', matches_path %>
|
||||
39
app/views/matches/index.html.erb
Normal file
39
app/views/matches/index.html.erb
Normal file
@@ -0,0 +1,39 @@
|
||||
<h1>Listing matches</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>R</th>
|
||||
<th>G</th>
|
||||
<th>G stat</th>
|
||||
<th>R stat</th>
|
||||
<th>Winner</th>
|
||||
<th>Win type</th>
|
||||
<th>Score</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @matches.each do |match| %>
|
||||
<tr>
|
||||
<td><%= match.r_id %></td>
|
||||
<td><%= match.g_id %></td>
|
||||
<td><%= match.g_stat %></td>
|
||||
<td><%= match.r_stat %></td>
|
||||
<td><%= match.winner_id %></td>
|
||||
<td><%= match.win_type %></td>
|
||||
<td><%= match.score %></td>
|
||||
<td><%= link_to 'Show', match %></td>
|
||||
<td><%= link_to 'Edit', edit_match_path(match) %></td>
|
||||
<td><%= link_to 'Destroy', match, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
<%= link_to 'New Match', new_match_path %>
|
||||
4
app/views/matches/index.json.jbuilder
Normal file
4
app/views/matches/index.json.jbuilder
Normal file
@@ -0,0 +1,4 @@
|
||||
json.array!(@matches) do |match|
|
||||
json.extract! match, :id, :r_id, :g_id, :g_stat, :r_stat, :winner_id, :win_type, :score
|
||||
json.url match_url(match, format: :json)
|
||||
end
|
||||
5
app/views/matches/new.html.erb
Normal file
5
app/views/matches/new.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>New match</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Back', matches_path %>
|
||||
39
app/views/matches/show.html.erb
Normal file
39
app/views/matches/show.html.erb
Normal file
@@ -0,0 +1,39 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<strong>R:</strong>
|
||||
<%= @match.r_id %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>G:</strong>
|
||||
<%= @match.g_id %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>G stat:</strong>
|
||||
<%= @match.g_stat %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>R stat:</strong>
|
||||
<%= @match.r_stat %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Winner:</strong>
|
||||
<%= @match.winner_id %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Win type:</strong>
|
||||
<%= @match.win_type %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Score:</strong>
|
||||
<%= @match.score %>
|
||||
</p>
|
||||
|
||||
<%= link_to 'Edit', edit_match_path(@match) %> |
|
||||
<%= link_to 'Back', matches_path %>
|
||||
1
app/views/matches/show.json.jbuilder
Normal file
1
app/views/matches/show.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.extract! @match, :id, :r_id, :g_id, :g_stat, :r_stat, :winner_id, :win_type, :score, :created_at, :updated_at
|
||||
@@ -42,7 +42,7 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @wrestlers.each do |wrestler| %>
|
||||
<% @wrestlers.order("weight_id asc").each do |wrestler| %>
|
||||
<% if wrestler.school_id == @school.id %>
|
||||
<tr>
|
||||
<td><%= wrestler.name %></td>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @wrestler.each do |wrestler| %>
|
||||
<% @wrestlers.order("original_seed asc").each do |wrestler| %>
|
||||
<% if wrestler.weight_id == @weight.id %>
|
||||
<tr>
|
||||
<td><%= wrestler.name %></td>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
Wrestling::Application.routes.draw do
|
||||
resources :matches
|
||||
|
||||
devise_for :users
|
||||
resources :tournaments
|
||||
|
||||
|
||||
15
db/migrate/20140124174110_create_matches.rb
Normal file
15
db/migrate/20140124174110_create_matches.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class CreateMatches < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :matches do |t|
|
||||
t.integer :r_id
|
||||
t.integer :g_id
|
||||
t.text :g_stat
|
||||
t.text :r_stat
|
||||
t.integer :winner_id
|
||||
t.string :win_type
|
||||
t.string :score
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
14
db/schema.rb
14
db/schema.rb
@@ -11,7 +11,19 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20140124021031) do
|
||||
ActiveRecord::Schema.define(version: 20140124174110) do
|
||||
|
||||
create_table "matches", force: true do |t|
|
||||
t.integer "r_id"
|
||||
t.integer "g_id"
|
||||
t.text "g_stat"
|
||||
t.text "r_stat"
|
||||
t.integer "winner_id"
|
||||
t.string "win_type"
|
||||
t.string "score"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "schools", force: true do |t|
|
||||
t.string "name"
|
||||
|
||||
49
test/controllers/matches_controller_test.rb
Normal file
49
test/controllers/matches_controller_test.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
require 'test_helper'
|
||||
|
||||
class MatchesControllerTest < ActionController::TestCase
|
||||
setup do
|
||||
@match = matches(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_not_nil assigns(:matches)
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get :new
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create match" do
|
||||
assert_difference('Match.count') do
|
||||
post :create, match: { g_id: @match.g_id, g_stat: @match.g_stat, r_id: @match.r_id, r_stat: @match.r_stat, score: @match.score, win_type: @match.win_type, winner_id: @match.winner_id }
|
||||
end
|
||||
|
||||
assert_redirected_to match_path(assigns(:match))
|
||||
end
|
||||
|
||||
test "should show match" do
|
||||
get :show, id: @match
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get :edit, id: @match
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update match" do
|
||||
patch :update, id: @match, match: { g_id: @match.g_id, g_stat: @match.g_stat, r_id: @match.r_id, r_stat: @match.r_stat, score: @match.score, win_type: @match.win_type, winner_id: @match.winner_id }
|
||||
assert_redirected_to match_path(assigns(:match))
|
||||
end
|
||||
|
||||
test "should destroy match" do
|
||||
assert_difference('Match.count', -1) do
|
||||
delete :destroy, id: @match
|
||||
end
|
||||
|
||||
assert_redirected_to matches_path
|
||||
end
|
||||
end
|
||||
19
test/fixtures/matches.yml
vendored
Normal file
19
test/fixtures/matches.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
r_id: 1
|
||||
g_id: 1
|
||||
g_stat: MyText
|
||||
r_stat: MyText
|
||||
winner_id: 1
|
||||
win_type: MyString
|
||||
score: MyString
|
||||
|
||||
two:
|
||||
r_id: 1
|
||||
g_id: 1
|
||||
g_stat: MyText
|
||||
r_stat: MyText
|
||||
winner_id: 1
|
||||
win_type: MyString
|
||||
score: MyString
|
||||
4
test/helpers/matches_helper_test.rb
Normal file
4
test/helpers/matches_helper_test.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
require 'test_helper'
|
||||
|
||||
class MatchesHelperTest < ActionView::TestCase
|
||||
end
|
||||
7
test/models/match_test.rb
Normal file
7
test/models/match_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class MatchTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Reference in New Issue
Block a user