From 874ae997cc0dc3740c2f94629867cdafed2ceae7 Mon Sep 17 00:00:00 2001 From: Jen Kelly Date: Tue, 19 Aug 2025 23:11:10 -0400 Subject: [PATCH 1/5] Write index, new, create actions and create routes --- app/controllers/puppies_controller.rb | 23 +++++++++++++++++++---- config/routes.rb | 6 +----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/controllers/puppies_controller.rb b/app/controllers/puppies_controller.rb index ed1730d..de39eab 100644 --- a/app/controllers/puppies_controller.rb +++ b/app/controllers/puppies_controller.rb @@ -1,6 +1,21 @@ 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 new + @puppy = Puppy.new + end + + def create + @puppy = Puppy.create(puppy_params) + @puppy.save + redirect_to puppy_path(@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..10013fb 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 :puppy, only: %i[index new create] end From 48453f19b27d99d4a1e1a6f07f1b8a98cc0c8870 Mon Sep 17 00:00:00 2001 From: Jen Kelly Date: Tue, 19 Aug 2025 23:13:24 -0400 Subject: [PATCH 2/5] Write getter/setter methods and initialize method --- app/models/puppy.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/models/puppy.rb b/app/models/puppy.rb index 77f6078..1cc6e68 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 From ab9215d4c70f5eea50abc4e9420657cd1a19d98b Mon Sep 17 00:00:00 2001 From: Jen Kelly Date: Tue, 19 Aug 2025 23:30:14 -0400 Subject: [PATCH 3/5] Create index page. Update to custom routes --- app/controllers/puppies_controller.rb | 1 - app/views/puppies/index.html.erb | 4 ++++ config/routes.rb | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/puppies_controller.rb b/app/controllers/puppies_controller.rb index de39eab..4994e2d 100644 --- a/app/controllers/puppies_controller.rb +++ b/app/controllers/puppies_controller.rb @@ -1,6 +1,5 @@ class PuppiesController < ApplicationController def index - @puppies = Puppy.all end def new diff --git a/app/views/puppies/index.html.erb b/app/views/puppies/index.html.erb index 2be4660..d46fe1d 100644 --- a/app/views/puppies/index.html.erb +++ b/app/views/puppies/index.html.erb @@ -1,3 +1,7 @@ +

Welcome to the Puppy Adoption Site

+ +<%= link_to "Click Here To List A Puppy", puppy_path %> + +<%= link_to "Click Here To List A Puppy", new_path %> diff --git a/app/views/puppies/new.html.erb b/app/views/puppies/new.html.erb index 45ca039..e2509ec 100644 --- a/app/views/puppies/new.html.erb +++ b/app/views/puppies/new.html.erb @@ -1,11 +1,23 @@ - +
+ <%= f.label :name %> + <%= f.text_field :name %> +
+ +
+ <%= f.label :breed %> + <%= f.text_field :breed %> +
+ +
+ <%= f.label :age %> + <%= f.number_field :age %> +
+ +
+ <%= f.submit "Submit" %> +
+<% end %> From ef6db182c72ed5006b58a134bc70abd1d2b4df15 Mon Sep 17 00:00:00 2001 From: Jen Kelly Date: Wed, 20 Aug 2025 00:14:48 -0400 Subject: [PATCH 5/5] Add create page to display puppy content --- app/controllers/puppies_controller.rb | 14 +++++--------- app/views/puppies/create.html.erb | 18 +++++++----------- app/views/puppies/new.html.erb | 2 +- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/app/controllers/puppies_controller.rb b/app/controllers/puppies_controller.rb index 4994e2d..222a7c6 100644 --- a/app/controllers/puppies_controller.rb +++ b/app/controllers/puppies_controller.rb @@ -7,14 +7,10 @@ def new end def create - @puppy = Puppy.create(puppy_params) - @puppy.save - redirect_to puppy_path(@puppy) - end - - private - - def puppy_params - params.require(:puppy).permit(:name, :breed, :age) + @puppy = Puppy.new( + name: params[:name], + breed: params[:breed], + age: params[:age] + ) end end diff --git a/app/views/puppies/create.html.erb b/app/views/puppies/create.html.erb index 6f54b98..bc1d9c4 100644 --- a/app/views/puppies/create.html.erb +++ b/app/views/puppies/create.html.erb @@ -1,11 +1,7 @@ - +
+
    +
  • Puppy Name: <%= @puppy.name %>
  • +
  • Puppy Breed: <%= @puppy.breed %>
  • +
  • Puppy Age: <%= @puppy.age %>
  • +
+
diff --git a/app/views/puppies/new.html.erb b/app/views/puppies/new.html.erb index e2509ec..cd4db5c 100644 --- a/app/views/puppies/new.html.erb +++ b/app/views/puppies/new.html.erb @@ -18,6 +18,6 @@
- <%= f.submit "Submit" %> + <%= submit_tag "submit" %>
<% end %>