Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions app/controllers/teams_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
class TeamsController < ApplicationController
# TODO: Add your controller actions here
# You'll need a 'new' action to display the form
# You'll need a 'create' action to process the form submission
def new
@team = Team.new
end

def create
@team = Team.new(team_params)
if @team.save
render :new, notice: 'Team created successfully!'
else
render :create
end
end

private

def team_params
params.require(:team).permit(:name, :coach, :pg, :sg, :pf, :sf, :c)
end
end
9 changes: 9 additions & 0 deletions app/models/team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Team < ApplicationRecord
validates :name, presence: true, uniqueness: true
validates :coach, presence: true
validates :pg, presence: true
validates :sg, presence: true
validates :pf, presence: true
validates :sf, presence: true
validates :c, presence: true
end
23 changes: 11 additions & 12 deletions app/views/teams/create.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
<title>Basketball Team</title>
</head>
<body>
<!--
TODO: Display the team information here!

Your view should display:
- Team Name: [team name]
- Coach: [coach name]
- Point Guard: [pg name]
- Shooting Guard: [sg name]
- Power Forward: [pf name]
- Small Forward: [sf name]
- Center: [c name]
<h1>Basketball Team</h1>


<p>Team Name: <%= @team.name %></p>
<p>Coach: <%= @team.coach %></p>
<p>Point Guard: <%= @team.pg %></p>
<p>Shooting Guard: <%= @team.sg %></p>
<p>Power Forward: <%= @team.pf %></p>
<p>Small Forward: <%= @team.sf %></p>
<p>Center: <%= @team.c %></p>


Use the data passed from your controller action.
-->
</body>
</html>
82 changes: 73 additions & 9 deletions app/views/teams/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,80 @@
<title>Basketball Team Signup</title>
</head>
<body>
<!--
TODO: Create your form here!

Your form should:
- Use Rails form helpers
- Submit to '/team' with POST method
- Have fields for: name, coach, pg, sg, pf, sf, c
- Have a submit button with id="Submit"
<h1> Basketball Team Signup</h1>

Hint: Use form_with helper
-->
<%= form_with model: @team, local: true do |form| %>
<% if @team.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@team.errors.count, "error") %> prevented this team from being saved:</h2>
<ul>
<% @team.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= form.label :name %>
<%= form.text_field :name, id: "name" %>
<% if @team.errors[:name].any? %>
<span class="error"><%= @team.errors[:name].first %></span>
<% end %>
</div>

<div class="field">
<%= form.label :coach %>
<%= form.text_field :coach, id: "coach" %>
<% if @team.errors[:coach].any? %>
<span class="error"><%= @team.errors[:coach].first %></span>
<% end %>
</div>

<div class="field">
<%= form.label :pg %>
<%= form.text_field :pg, id: "pg" %>
<% if @team.errors[:pg].any? %>
<span class="error"><%= @team.errors[:pg].first %></span>
<% end %>
</div>

<div class="field">
<%= form.label :sg %>
<%= form.text_field :sg, id: "sg" %>
<% if @team.errors[:sg].any? %>
<span class="error"><%= @team.errors[:sg].first %></span>
<% end %>
</div>

<div class="field">
<%= form.label :pf %>
<%= form.text_field :pf, id: "pf" %>
<% if @team.errors[:pf].any? %>
<span class="error"><%= @team.errors[:pf].first %></span>
<% end %>
</div>

<div class="field">
<%= form.label :sf %>
<%= form.text_field :sf, id: "sf" %>
<% if @team.errors[:sf].any? %>
<span class="error"><%= @team.errors[:sf].first %></span>
<% end %>
</div>

<div class="field">
<%= form.label :c %>
<%= form.text_field :c, id: "c" %>
<% if @team.errors[:c].any? %>
<span class="error"><%= @team.errors[:c].first %></span>
<% end %>
</div>

<div class="actions">
<%= form.submit "Submit" %>
</div>
<% end %>
</body>
</html>
6 changes: 2 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Rails.application.routes.draw do
# TODO: Add your routes here
# You need:
# - A GET route to '/newteam' that goes to the teams controller new action
# - A POST route to '/team' that goes to the teams controller create action
get '/newteam', to: 'teams#new'
post '/teams', to: 'teams#create'
end
15 changes: 15 additions & 0 deletions db/migrate/20250819171041_create_teams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CreateTeams < ActiveRecord::Migration[6.1]
def change
create_table :teams do |t|
t.string :name
t.string :coach
t.string :pg
t.string :sg
t.string :pf
t.string :sf
t.string :c

t.timestamps
end
end
end
25 changes: 12 additions & 13 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 0) do
ActiveRecord::Schema.define(version: 20_250_819_171_041) do
create_table 'teams', force: :cascade do |t|
t.string 'name'
t.string 'coach'
t.string 'pg'
t.string 'sg'
t.string 'pf'
t.string 'sf'
t.string 'c'
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
end
end
2 changes: 2 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Team.create(name: 'PHRG Ballers', coach: 'Stove McKeon', pg: 'Shantel Grey', sg: 'Kyle Housel', pf: 'Mike Clancy',
sf: 'Emily Kanarek', c: 'Nihar Patel')