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
37 changes: 34 additions & 3 deletions app/controllers/teams_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
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 index
@teams = Team.all
end

def show
@team = Team.find(params[:id])
end

def new
@team = Team.new
end

def create
@team = Team.new(team_params)
@team.save
redirect_to @team
end

def edit
@team = Team.find(params[:id])
end

def update
@team = Team.find(params[:id])
@team.update(team_params)
redirect_to @team
end

private

def team_params
params.require(:team).permit(:name, :coach, :pg, :sg, :pf, :sf, :c)
end
end
2 changes: 2 additions & 0 deletions app/models/team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Team < ApplicationRecord
end
23 changes: 0 additions & 23 deletions app/views/teams/create.html.erb

This file was deleted.

52 changes: 41 additions & 11 deletions app/views/teams/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,49 @@
<html>
<head>
<meta charset="UTF-8">
<title>Basketball Team Signup</title>
<title>Create Team</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"

Hint: Use form_with helper
-->
<h1>New Team</h1>

<%= form_with url: '/team', method: :post, local: true do |form| %>
<div>
<%= form.label :name, "Team Name:" %>
<%= form.text_field :name, name: 'team[name]' %>
</div>

<div>
<%= form.label :coach, "Coach:" %>
<%= form.text_field :coach, name: 'team[coach]' %>
</div>

<div>
<%= form.label :pg, "Point Guard:" %>
<%= form.text_field :pg, name: 'team[pg]' %>
</div>

<div>
<%= form.label :sg, "Shooting Guard:" %>
<%= form.text_field :sg, name: 'team[sg]' %>
</div>

<div>
<%= form.label :pf, "Power Forward:" %>
<%= form.text_field :pf, name: 'team[pf]' %>
</div>

<div>
<%= form.label :sf, "Small Forward:" %>
<%= form.text_field :sf, name: 'team[sf]' %>
</div>

<div>
<%= form.label :c, "Center:" %>
<%= form.text_field :c, name: 'team[c]' %>
</div>

<%= form.submit "Submit", id: "Submit" %>
<% end %>
</body>
</html>
22 changes: 22 additions & 0 deletions app/views/teams/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Team Details</title>
</head>
<body>

<h1>Team Details:</h1>

<div>
<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>
</div>

</body>
</html>
8 changes: 4 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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
resources :teams
get '/newteam', to: 'teams#new'
post '/team', to: 'teams#create'
get '/team/:id', to: 'teams#show'
end
Binary file modified db/development.sqlite3
Binary file not shown.
15 changes: 15 additions & 0 deletions db/migrate/20250819130055_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
15 changes: 14 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,18 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 0) do
ActiveRecord::Schema.define(version: 2025_08_19_130055) 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
Binary file modified db/test.sqlite3
Binary file not shown.