From 3efb8270181d927f1b73bb12c3eaa51ce38dab46 Mon Sep 17 00:00:00 2001 From: Stephen McKeon Date: Thu, 21 Aug 2025 09:05:38 -0400 Subject: [PATCH 1/3] Display all puppies --- app/controllers/puppies_controller.rb | 10 +++------- app/views/puppies/index.html.erb | 21 ++++++++++++--------- config/routes.rb | 5 +---- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/app/controllers/puppies_controller.rb b/app/controllers/puppies_controller.rb index d682f57..ac6d06a 100644 --- a/app/controllers/puppies_controller.rb +++ b/app/controllers/puppies_controller.rb @@ -1,9 +1,5 @@ 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 redirect to show - # You'll need a 'show' action to display the puppy information - # - # Remember: After creating a puppy, you should redirect to the show page + def index + @puppies = Puppy.all + end end diff --git a/app/views/puppies/index.html.erb b/app/views/puppies/index.html.erb index 237462e..643305b 100644 --- a/app/views/puppies/index.html.erb +++ b/app/views/puppies/index.html.erb @@ -1,10 +1,13 @@ - +<%= link_to "Click Here To List A Puppy", new_puppy_path %> diff --git a/config/routes.rb b/config/routes.rb index 07741f6..857ce39 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,3 @@ Rails.application.routes.draw do - # TODO: Add your routes here - # You need to use RESTful routing conventions - # Hint: Use the resources method to create all the standard RESTful routes - # This will create routes for index, show, new, create, edit, update, and destroy + resources :puppies, only: [:index, :show, :new, :create] end From 6319cdc35ec1249cad9f59cfd9f61ea8f6218850 Mon Sep 17 00:00:00 2001 From: Stephen McKeon Date: Thu, 21 Aug 2025 09:11:52 -0400 Subject: [PATCH 2/3] Create puppy form --- app/controllers/puppies_controller.rb | 4 ++++ app/views/puppies/new.html.erb | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/controllers/puppies_controller.rb b/app/controllers/puppies_controller.rb index ac6d06a..6d0d5bc 100644 --- a/app/controllers/puppies_controller.rb +++ b/app/controllers/puppies_controller.rb @@ -2,4 +2,8 @@ class PuppiesController < ApplicationController def index @puppies = Puppy.all end + + def new + @puppy = Puppy.new + end end diff --git a/app/views/puppies/new.html.erb b/app/views/puppies/new.html.erb index 7eacde8..2aaee08 100644 --- a/app/views/puppies/new.html.erb +++ b/app/views/puppies/new.html.erb @@ -10,3 +10,18 @@ Hint: Use form_with helper with a model parameter instead of url parameter This will automatically set the correct action and method --> + +<%= form_with model: @puppy, local: true do |form| %> + <%= form.label :name %> + <%= form.text_field :name %> + +

+ + <%= form.label :breed %> + <%= form.text_field :breed %> + +

+ + <%= form.label :age %> + <%= form.text_field :age %> +<% end %> From 19eb65528eeda1e1c7ee9c45d10543583342c468 Mon Sep 17 00:00:00 2001 From: Stephen McKeon Date: Thu, 21 Aug 2025 09:32:59 -0400 Subject: [PATCH 3/3] Create and display puppy on form submission --- app/controllers/puppies_controller.rb | 15 +++++++++++++++ app/views/puppies/new.html.erb | 4 ++++ app/views/puppies/show.html.erb | 14 +++----------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/controllers/puppies_controller.rb b/app/controllers/puppies_controller.rb index 6d0d5bc..28810c9 100644 --- a/app/controllers/puppies_controller.rb +++ b/app/controllers/puppies_controller.rb @@ -3,7 +3,22 @@ def index @puppies = Puppy.all end + def show + @puppy = Puppy.find(params[:id]) + end + def new @puppy = Puppy.new end + + def create + puppy = Puppy.create!(puppy_params) + redirect_to puppy_path(puppy) + end + + private + + def puppy_params + params.require(:puppy).permit(:name, :breed, :age) + end end diff --git a/app/views/puppies/new.html.erb b/app/views/puppies/new.html.erb index 2aaee08..546e5eb 100644 --- a/app/views/puppies/new.html.erb +++ b/app/views/puppies/new.html.erb @@ -24,4 +24,8 @@ <%= form.label :age %> <%= form.text_field :age %> + +

+ + <%= form.submit id: "submit" %> <% end %> diff --git a/app/views/puppies/show.html.erb b/app/views/puppies/show.html.erb index b8ad62d..ed00ef6 100644 --- a/app/views/puppies/show.html.erb +++ b/app/views/puppies/show.html.erb @@ -1,11 +1,3 @@ - +

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

+

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

+

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