From b682f4ef65df5ae14acb704fda7038b40abd6396 Mon Sep 17 00:00:00 2001 From: Nihar Patel Date: Tue, 19 Aug 2025 10:11:41 -0400 Subject: [PATCH 1/7] Create Puppies routes and Controller actions --- app/controllers/puppies_controller.rb | 27 +++++++++++++++++++++++---- config/routes.rb | 6 +----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/controllers/puppies_controller.rb b/app/controllers/puppies_controller.rb index ed1730d..9a8af42 100644 --- a/app/controllers/puppies_controller.rb +++ b/app/controllers/puppies_controller.rb @@ -1,6 +1,25 @@ class PuppiesController < ApplicationController - # TODO: Add your controller actions here - # You'll need an 'index' action to display the homepage - # You'll need a 'new' action to display the form - # You'll need a 'create' action to process the form submission and display the puppy + def index + @puppies = Puppy.all + end + + def show + @puppy = Puppy.find(params[:id]) + end + + def new + @puppy = Puppy.new + end + + def create + @puppy = Puppy.new(puppy_params) + @puppy.save + redirect_to @puppy + end + + private + + def puppy_params + params.require(:puppy).permit(:name, :breed, :age) + end end diff --git a/config/routes.rb b/config/routes.rb index 4c97056..c8a40e0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,3 @@ Rails.application.routes.draw do - # TODO: Add your routes here - # You need: - # - A GET route to '/' that goes to the puppies controller index action - # - A GET route to '/new' that goes to the puppies controller new action - # - A POST route to '/puppy' that goes to the puppies controller create action + resources :puppies, only: %i[index create post show] end From 48080b38afdf275355778e0eb532eefdf8f07121 Mon Sep 17 00:00:00 2001 From: Nihar Patel Date: Tue, 19 Aug 2025 10:15:58 -0400 Subject: [PATCH 2/7] Create Accessor and Initialize methods for Puppies model --- models/puppy.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/models/puppy.rb b/models/puppy.rb index 77f6078..1a38e33 100644 --- a/models/puppy.rb +++ b/models/puppy.rb @@ -1,10 +1,9 @@ -# TODO: Build out your Puppy class here -# Your puppy should have name, breed, and age attributes -# You will need to be able to pass these three attributes to initialization -# as well as readers and writers for the attributes - class Puppy - # TODO: Add your code here - # Hint: You'll need attr_accessor for name, breed, and age - # You'll also need an initialize method that takes name, breed, and age as parameters + attr_accessor :name, :breed, :age + + def initialize(name, breed, age) + @name = name + @breed = breed + @age = age + end end From 52f3ed541fb15710d34a73d29169862c04a39940 Mon Sep 17 00:00:00 2001 From: Nihar Patel Date: Tue, 19 Aug 2025 10:22:20 -0400 Subject: [PATCH 3/7] deleted the duplicate models/puppy.rb --- app/models/puppy.rb | 15 +++++++-------- config/routes.rb | 2 +- models/puppy.rb | 9 --------- 3 files changed, 8 insertions(+), 18 deletions(-) delete mode 100644 models/puppy.rb diff --git a/app/models/puppy.rb b/app/models/puppy.rb index 77f6078..2b54bed 100644 --- a/app/models/puppy.rb +++ b/app/models/puppy.rb @@ -1,10 +1,9 @@ -# TODO: Build out your Puppy class here -# Your puppy should have name, breed, and age attributes -# You will need to be able to pass these three attributes to initialization -# as well as readers and writers for the attributes - class Puppy - # TODO: Add your code here - # Hint: You'll need attr_accessor for name, breed, and age - # You'll also need an initialize method that takes name, breed, and age as parameters + attr_accessor :name, :breed, :age + + def initialize(name, breed, age) + @name = name + @breed = breed + @age = age + end end diff --git a/config/routes.rb b/config/routes.rb index c8a40e0..857ce39 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,3 @@ Rails.application.routes.draw do - resources :puppies, only: %i[index create post show] + resources :puppies, only: [:index, :show, :new, :create] end diff --git a/models/puppy.rb b/models/puppy.rb deleted file mode 100644 index 1a38e33..0000000 --- a/models/puppy.rb +++ /dev/null @@ -1,9 +0,0 @@ -class Puppy - attr_accessor :name, :breed, :age - - def initialize(name, breed, age) - @name = name - @breed = breed - @age = age - end -end From b8e217e271b7d3e81926875e6ed4176cc770ec80 Mon Sep 17 00:00:00 2001 From: Nihar Patel Date: Tue, 19 Aug 2025 10:31:17 -0400 Subject: [PATCH 4/7] Update routes --- config/routes.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 857ce39..749b953 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ Rails.application.routes.draw do - resources :puppies, only: [:index, :show, :new, :create] + get '/', to: 'puppies#index' + get '/new', to: 'puppies#new' + post '/puppy', to: 'puppies#create' end From d65677dd1e66a6b11516b6e90ec5d616a0fef574 Mon Sep 17 00:00:00 2001 From: Nihar Patel Date: Tue, 19 Aug 2025 10:36:31 -0400 Subject: [PATCH 5/7] Create index.html.erb page --- app/views/puppies/index.html.erb | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/app/views/puppies/index.html.erb b/app/views/puppies/index.html.erb index 2be4660..bf32704 100644 --- a/app/views/puppies/index.html.erb +++ b/app/views/puppies/index.html.erb @@ -1,10 +1,3 @@ - +<%= link_to "Click Here To List A Puppy", "/new" %> From b3f38008bc63f7a9599bfeba661bd029b7762428 Mon Sep 17 00:00:00 2001 From: Nihar Patel Date: Tue, 19 Aug 2025 10:48:03 -0400 Subject: [PATCH 6/7] Update controller to take Ruby class instances, not db --- app/controllers/puppies_controller.rb | 10 ++++------ app/views/puppies/new.html.erb | 19 ++++++++++--------- db/schema.rb | 3 ++- db/test.sqlite3 | Bin 20480 -> 20480 bytes 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/controllers/puppies_controller.rb b/app/controllers/puppies_controller.rb index 9a8af42..7159c46 100644 --- a/app/controllers/puppies_controller.rb +++ b/app/controllers/puppies_controller.rb @@ -1,25 +1,23 @@ class PuppiesController < ApplicationController def index - @puppies = Puppy.all + @puppies = [] end def show - @puppy = Puppy.find(params[:id]) end def new - @puppy = Puppy.new + @puppy = Puppy.new("", "", "") end def create @puppy = Puppy.new(puppy_params) - @puppy.save - redirect_to @puppy + render :create end private def puppy_params - params.require(:puppy).permit(:name, :breed, :age) + params.permit(:name, :breed, :age) end end diff --git a/app/views/puppies/new.html.erb b/app/views/puppies/new.html.erb index 45ca039..5ea3b6b 100644 --- a/app/views/puppies/new.html.erb +++ b/app/views/puppies/new.html.erb @@ -1,11 +1,12 @@ - + <%= form.label :age %> + <%= form.text_field :age %> + + <%= form.submit "submit" %> +<% end %> diff --git a/db/schema.rb b/db/schema.rb index ae89000..1879966 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,5 +10,6 @@ # # 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_143654) do + end diff --git a/db/test.sqlite3 b/db/test.sqlite3 index 9fb98b53db80e34f7b4801c010ce42d897871fe2..f973236bc061f9804c978dabaa916935103d7f8b 100644 GIT binary patch delta 220 zcmZozz}T>WaRZwG%R2`Ccbf$Tp76^EFfwTx85o%wSQuIwni!jzns6~NFfj7NRR{?( zYjUEh*klmJACqiuW?*cQW@%uaXquK}mS%1O)Shf;VVrD~mSkdPWMp7rY;KyE2-2!+ uV4-VhsbFYgWo&6>XrX6jX<=kwj9X^%HhXz(6!qrD1}50mgJc#t2mk=H@-n3W delta 200 zcmZozz}T>WaRZwG%Wnq$- Date: Tue, 19 Aug 2025 10:58:41 -0400 Subject: [PATCH 7/7] Update create.erb and update other things to accept ruby classes --- app/controllers/puppies_controller.rb | 8 +------- app/views/puppies/create.html.erb | 14 ++++---------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/app/controllers/puppies_controller.rb b/app/controllers/puppies_controller.rb index 7159c46..b5cd7fc 100644 --- a/app/controllers/puppies_controller.rb +++ b/app/controllers/puppies_controller.rb @@ -11,13 +11,7 @@ def new end def create - @puppy = Puppy.new(puppy_params) + @puppy = Puppy.new(params[:name], params[:breed], params[:age]) render :create end - - private - - def puppy_params - params.permit(:name, :breed, :age) - end end diff --git a/app/views/puppies/create.html.erb b/app/views/puppies/create.html.erb index 6f54b98..21d5f67 100644 --- a/app/views/puppies/create.html.erb +++ b/app/views/puppies/create.html.erb @@ -1,11 +1,5 @@ - +

Puppy Name: <%= @puppy.name %>

+

Puppy Breed: <%= @puppy.breed %>

+

Puppy Age: <%= @puppy.age %>