diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index d8cd2dc..a15e946 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -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 diff --git a/app/models/team.rb b/app/models/team.rb new file mode 100644 index 0000000..1b671b6 --- /dev/null +++ b/app/models/team.rb @@ -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 diff --git a/app/views/teams/create.html.erb b/app/views/teams/create.html.erb index 3d56f29..5f381bc 100644 --- a/app/views/teams/create.html.erb +++ b/app/views/teams/create.html.erb @@ -5,19 +5,18 @@ Basketball Team - diff --git a/app/views/teams/new.html.erb b/app/views/teams/new.html.erb index 4be4bef..5746254 100644 --- a/app/views/teams/new.html.erb +++ b/app/views/teams/new.html.erb @@ -5,16 +5,80 @@ Basketball Team Signup - + <%= form_with model: @team, local: true do |form| %> + <% if @team.errors.any? %> +
+

<%= pluralize(@team.errors.count, "error") %> prevented this team from being saved:

+ +
+ <% end %> + +
+ <%= form.label :name %> + <%= form.text_field :name, id: "name" %> + <% if @team.errors[:name].any? %> + <%= @team.errors[:name].first %> + <% end %> +
+ +
+ <%= form.label :coach %> + <%= form.text_field :coach, id: "coach" %> + <% if @team.errors[:coach].any? %> + <%= @team.errors[:coach].first %> + <% end %> +
+ +
+ <%= form.label :pg %> + <%= form.text_field :pg, id: "pg" %> + <% if @team.errors[:pg].any? %> + <%= @team.errors[:pg].first %> + <% end %> +
+ +
+ <%= form.label :sg %> + <%= form.text_field :sg, id: "sg" %> + <% if @team.errors[:sg].any? %> + <%= @team.errors[:sg].first %> + <% end %> +
+ +
+ <%= form.label :pf %> + <%= form.text_field :pf, id: "pf" %> + <% if @team.errors[:pf].any? %> + <%= @team.errors[:pf].first %> + <% end %> +
+ +
+ <%= form.label :sf %> + <%= form.text_field :sf, id: "sf" %> + <% if @team.errors[:sf].any? %> + <%= @team.errors[:sf].first %> + <% end %> +
+ +
+ <%= form.label :c %> + <%= form.text_field :c, id: "c" %> + <% if @team.errors[:c].any? %> + <%= @team.errors[:c].first %> + <% end %> +
+ +
+ <%= form.submit "Submit" %> +
+ <% end %> diff --git a/config/routes.rb b/config/routes.rb index 0536571..65d4c01 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20250819171041_create_teams.rb b/db/migrate/20250819171041_create_teams.rb new file mode 100644 index 0000000..fb05523 --- /dev/null +++ b/db/migrate/20250819171041_create_teams.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index ae89000..08e2960 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000..7dc2f66 --- /dev/null +++ b/db/seeds.rb @@ -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')