From 2b9d596e3f5928c0c6ab2779ed5ea5ea6080edbd Mon Sep 17 00:00:00 2001 From: Shantel Date: Tue, 19 Aug 2025 22:48:14 -0400 Subject: [PATCH 1/2] Basic Lab 1 --- app/controllers/teams_controller.rb | 25 ++++++++-- app/models/team.rb | 2 + app/views/teams/create.html.erb | 23 --------- app/views/teams/new.html.erb | 55 +++++++++++++++------- app/views/teams/show.html.erb | 10 ++++ config/routes.rb | 2 + db/development.sqlite3 | Bin 0 -> 28672 bytes db/migrate/20250820012730_create_teams.rb | 15 ++++++ db/schema.rb | 15 +++++- db/test.sqlite3 | Bin 20480 -> 28672 bytes 10 files changed, 104 insertions(+), 43 deletions(-) create mode 100644 app/models/team.rb delete mode 100644 app/views/teams/create.html.erb create mode 100644 app/views/teams/show.html.erb create mode 100644 db/migrate/20250820012730_create_teams.rb diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index d8cd2dc..299038d 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -1,5 +1,24 @@ 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 = {} + end + + def create + @team = { + name: params[:name], + coach: params[:coach], + pg: params[:pg], + sg: params[:sg], + pf: params[:pf], + sf: params[:sf], + c: params[:c] + } + render :show + 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..48a6c83 --- /dev/null +++ b/app/models/team.rb @@ -0,0 +1,2 @@ +class Team < ApplicationRecord +end diff --git a/app/views/teams/create.html.erb b/app/views/teams/create.html.erb deleted file mode 100644 index 3d56f29..0000000 --- a/app/views/teams/create.html.erb +++ /dev/null @@ -1,23 +0,0 @@ - - - - - Basketball Team - - - - - diff --git a/app/views/teams/new.html.erb b/app/views/teams/new.html.erb index 4be4bef..53e7ea5 100644 --- a/app/views/teams/new.html.erb +++ b/app/views/teams/new.html.erb @@ -1,20 +1,43 @@ - - - - - Basketball Team Signup - - - +
+ <%= form.label :pg, "Point Guard" %> + <%= form.text_field :pg %> +
+ +
+ <%= form.label :sg, "Shooting Guard" %> + <%= form.text_field :sg %> +
+ +
+ <%= form.label :pf, "Power Forward" %> + <%= form.text_field :pf %> +
+ +
+ <%= form.label :sf, "Small Forward" %> + <%= form.text_field :sf %> +
+ +
+ <%= form.label :c, "Center" %> + <%= form.text_field :c %> +
+ +
+ <%= form.submit "Submit"%> +
+ <% end %> diff --git a/app/views/teams/show.html.erb b/app/views/teams/show.html.erb new file mode 100644 index 0000000..7c0834a --- /dev/null +++ b/app/views/teams/show.html.erb @@ -0,0 +1,10 @@ +

Basketball Team

+
+

Team Name: <%= @team[:name] %>

+

Coach: <%= @team[:coach] %>

+

Point Guard: <%= @team[:pg] %>

+

Shooting Guard: <%= @team[:sg] %>

+

Power Forward: <%= @team[:pf] %>

+

Small Forward: <%= @team[:sf] %>

+

Center: <%= @team[:c] %>

+
diff --git a/config/routes.rb b/config/routes.rb index 0536571..83b5c6d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,4 +3,6 @@ # 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 '/team', to: 'teams#create' end diff --git a/db/development.sqlite3 b/db/development.sqlite3 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..ac8c454d2b2da48b115f748d3d018d19b06c2a39 100644 GIT binary patch literal 28672 zcmeI)PjAv-90%~HV=K-KIunx~JouzsM)t3O2+WJs5VMTIL^v!Sn#b~NYorC*LgsPP zlP_U!Vkh5~F_|ZiK4lvz47})J!EeI@&)@R=K5d#jJPGgKR_uV&qmJjWfab_5ktFhx zQbLF zclV9@A>AtnJmy~OXLFE;cL&+(TViCVZ-b$>9a;GuIBU7`QFfid1e@>=d!lx z@PLWYY+Bvo2y-YktxE{^k$)OZcr>jjp|BaSc7Gh}AB6R0QC8pQC1SfRetL7Suzt`P zmd$C?H8ay{mrkX)y1gx(J-xm|trPAr)3J{|7T6uv_a`eB#$oQXhbjZ^`C{;&Wzxoi ztTwl2g>dJ@X68;+OgvE@gin=(NRsk{h!+kBKmY;|fB*y_009U<00Izz00ibjU{zX3 zXZ37eFJ^T;lP%=*haxVl|L5Z3A_xdT00Izz00bZa0SG_<0uX?}jliQ=dU<^Pf4%>I zNt8<z{}fB*y_009U<00Izz00ba#PXubxQYvK_+#T3n$91?HwD^FxJKZoFuIxAU z;%25qGsT@;W+z+P%Ibw;>Dla->;3;LqFmjR2r&%^KmY;|fB*y_009U<00Izz00jPC zAQ?+7M}9sC_y5J8{^5WC1Rwwb2tWV=5P$##AOHafKwypqu>POpi;K`8009U<00Izz Q00bZa0SG_<0yhG`0e=Hg1poj5 literal 0 HcmV?d00001 diff --git a/db/migrate/20250820012730_create_teams.rb b/db/migrate/20250820012730_create_teams.rb new file mode 100644 index 0000000..fb05523 --- /dev/null +++ b/db/migrate/20250820012730_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..c90891c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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_20_012730) 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/test.sqlite3 b/db/test.sqlite3 index d5994e4f180035d0b4c512b0863bd3e93ccc668b..59c9f4bb892369d9cf22f4fe5c7747fe79db8f40 100644 GIT binary patch delta 632 zcmZozz}WDBae}lU8v_FaI}pPF^F$qENj3((E)ib7SqyAEdl~q?@GauK%NNeGmv_p> zMpqu@#t_!Ya(pI?Y?Fie768dFd~VF_70i=u`SloCCg<>b0m<$B4)v@+GdV!!1~9RS zYilz`mLw+Sq!t(EWR|4H7pE4MrsgH1bD5okTpdGP6+#@Hd|VaK)N14<=BDZZb!s+o zGO~+{i!(MCg3T;RP0TF@6HEyG^*{rZz=BE&8cLZdN(z~IC8_DDMG65yp1zJjkqX|f zkqVBXA^x6zKwZABejy5e{y-e+p)9c|IU}(M$WP8sOwK?SC`d=<6{GM9 z(v%b=5qgV(Tm&z9@*=(fHeOK32y7MsnQg3OwnC@MDp*N^6pHZV7}G)Xi!Pc%xjv@|wMGe}9ZNHtC| zPEIvSwKOs`FiAACOg2hO18LPYu+TL!P%tpGGP1BTFwrwHGB>p_#3?g*tG&Dqs(Le1 N3j^%xK{AUR1ON%ZrXm0U delta 308 zcmZp8z}T>Wae}lUD+2=q2*Uu=L>*&MRtCMIMZEk!7+CnE8ThUFxAIBzecCK2u$-5< zF@$;Y0Ui@ZmdRgv7O=9giAS4Gj^&e>yopzfnYDs(@_k-CMyAPpd|p5@lFvby8E7yE z$Z%dDX5|0P!2cU)(0hJC1_owECVm4hRADv-1{P+1&dvY*qxqxFlT6Li42_da5-ltZ z4GqkalZ?#F(k#u5jgl=B6H}6tQWH~COj68@42(>54J>pGjT8*ctqe@93=Qy a4ROj$-Wo5jgQDKR(%2ZgNnn{p2?7ASu0v7) From 226e98108379d6356a37399332a3892aafafff97 Mon Sep 17 00:00:00 2001 From: Shantel Date: Wed, 20 Aug 2025 10:41:14 -0400 Subject: [PATCH 2/2] Update Baic Rails Lab --- Gemfile | 2 +- Gemfile.lock | 5 ++++ app/controllers/teams_controller.rb | 13 ++--------- app/views/teams/create.html.erb | 10 ++++++++ app/views/teams/new.html.erb | 34 ++++++++++++++++------------ app/views/teams/show.html.erb | 10 -------- db/development.sqlite3 | Bin 28672 -> 28672 bytes 7 files changed, 37 insertions(+), 37 deletions(-) create mode 100644 app/views/teams/create.html.erb delete mode 100644 app/views/teams/show.html.erb diff --git a/Gemfile b/Gemfile index 1a1b15d..8de6415 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,7 @@ gem 'fiddle' gem 'logger' gem 'mutex_m' gem 'ostruct' - +gem 'pry' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' gem 'rails', '~> 6.1.3', '>= 6.1.3.1' # Use sqlite3 as the database for Active Record (updated for Ruby 3.3 compatibility) diff --git a/Gemfile.lock b/Gemfile.lock index caea9fb..b96a561 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,6 +76,7 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) + coderay (1.1.3) concurrent-ruby (1.3.5) crass (1.0.6) date (3.4.1) @@ -131,6 +132,9 @@ GEM ast (~> 2.4.1) racc prism (1.4.0) + pry (0.15.2) + coderay (~> 1.1) + method_source (~> 1.0) public_suffix (6.0.2) puma (5.6.9) nio4r (~> 2.0) @@ -253,6 +257,7 @@ DEPENDENCIES mutex_m nio4r (~> 2.7) ostruct + pry puma (~> 5.0) rack-cors rails (~> 6.1.3, >= 6.1.3.1) diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index 299038d..89fccec 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -1,19 +1,10 @@ class TeamsController < ApplicationController def new - @team = {} + @team = Team.new end def create - @team = { - name: params[:name], - coach: params[:coach], - pg: params[:pg], - sg: params[:sg], - pf: params[:pf], - sf: params[:sf], - c: params[:c] - } - render :show + @team = Team.create(team_params) end private diff --git a/app/views/teams/create.html.erb b/app/views/teams/create.html.erb new file mode 100644 index 0000000..2e5eda0 --- /dev/null +++ b/app/views/teams/create.html.erb @@ -0,0 +1,10 @@ +

Basketball Team

+
+

Team Name: <%= @team.name %>

+

Coach: <%= @team.coach %>

+

Point Guard: <%= @team.pg%>

+

Shooting Guard: <%= @team.sg %>

+

Power Forward: <%= @team.pf%>

+

Small Forward: <%= @team.sf %>

+

Center: <%= @team.c %>

+
diff --git a/app/views/teams/new.html.erb b/app/views/teams/new.html.erb index 53e7ea5..d53f2e3 100644 --- a/app/views/teams/new.html.erb +++ b/app/views/teams/new.html.erb @@ -1,38 +1,39 @@

New Basketball Team

- <%= form_with url: '/team', local: true do |form| %> + + <%= form_with model: @team, url: '/team' do |form| %>
- <%= form.label :name, "Team Name" %> - <%= form.text_field :name %> + <%= form.label :name %> + <%= form.text_field :name, id: "name"%>
- <%= form.label :coach, "Coach" %> - <%= form.text_field :coach %> + <%= form.label :coach %> + <%= form.text_field :coach, id: "coach"%>
- <%= form.label :pg, "Point Guard" %> - <%= form.text_field :pg %> + <%= form.label :pg %> + <%= form.text_field :pg, id: "pg"%>
- <%= form.label :sg, "Shooting Guard" %> - <%= form.text_field :sg %> + <%= form.label :sg %> + <%= form.text_field :sg, id: "sg" %>
- <%= form.label :pf, "Power Forward" %> - <%= form.text_field :pf %> + <%= form.label :pf %> + <%= form.text_field :pf, id: "pf" %>
- <%= form.label :sf, "Small Forward" %> - <%= form.text_field :sf %> + <%= form.label :sf%> + <%= form.text_field :sf, id: "sf" %>
- <%= form.label :c, "Center" %> - <%= form.text_field :c %> + <%= form.label :c %> + <%= form.text_field :c, id: "c" %>
@@ -41,3 +42,6 @@ <% end %> + + +#url: use it for a path instead. diff --git a/app/views/teams/show.html.erb b/app/views/teams/show.html.erb deleted file mode 100644 index 7c0834a..0000000 --- a/app/views/teams/show.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -

Basketball Team

-
-

Team Name: <%= @team[:name] %>

-

Coach: <%= @team[:coach] %>

-

Point Guard: <%= @team[:pg] %>

-

Shooting Guard: <%= @team[:sg] %>

-

Power Forward: <%= @team[:pf] %>

-

Small Forward: <%= @team[:sf] %>

-

Center: <%= @team[:c] %>

-
diff --git a/db/development.sqlite3 b/db/development.sqlite3 index ac8c454d2b2da48b115f748d3d018d19b06c2a39..2120f391ebefc23b0b0fc14d76392a079f8b82d8 100644 GIT binary patch delta 259 zcmZp8z}WDBae_1>=R_H2M$U~1OZ>T*`E42a_w(2B+in&V(C4qWXXa+$g#brKBLgE- zT>}eUBLf9P6DwmwD^o)~a}xt&OLN>Z_Dr}9Ft9SP)HAg-G`6rnGXN&z2b8jBZnHiayn;D^+fGooc)Xm8Mm4W~3X2F2h{M?+3%;JnCsfoG8%m6MTGNb?i delta 45 scmZp8z}WDBae_1>+e8^>Mz)O!OZ=G_1U3sMJmH@>L5z);0SMq+06_l@K>z>%