From a719b818ea8e277c24e92105c468b293d54ecc40 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Tue, 19 Aug 2025 09:11:41 -0400 Subject: [PATCH 1/9] Delete extra models folder --- models/puppy.rb | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 models/puppy.rb diff --git a/models/puppy.rb b/models/puppy.rb deleted file mode 100644 index 77f6078..0000000 --- a/models/puppy.rb +++ /dev/null @@ -1,10 +0,0 @@ -# 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 -end From 8d910b8cef5443b2ba6e6e73580beba71d9ff194 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Tue, 19 Aug 2025 09:12:01 -0400 Subject: [PATCH 2/9] Create puppies table --- db/migrate/20250819130857_create_puppies.rb | 10 ++++++++++ db/schema.rb | 11 ++++++++++- db/test.sqlite3 | Bin 20480 -> 28672 bytes 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20250819130857_create_puppies.rb diff --git a/db/migrate/20250819130857_create_puppies.rb b/db/migrate/20250819130857_create_puppies.rb new file mode 100644 index 0000000..505123a --- /dev/null +++ b/db/migrate/20250819130857_create_puppies.rb @@ -0,0 +1,10 @@ +class CreatePuppies < ActiveRecord::Migration[6.1] + def change + create_table :puppies do |t| + t.string :name + t.string :breed + t.integer :age + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index ae89000..f759222 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,5 +10,14 @@ # # 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_130857) do + + create_table "puppies", force: :cascade do |t| + t.string "name" + t.string "breed" + t.integer "age" + 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 9fb98b53db80e34f7b4801c010ce42d897871fe2..cba197d967d6017b48e32fccd0dc032fdfaeeef0 100644 GIT binary patch delta 606 zcmZozz}WDBae}lU8v_FaI}pPF^F$qENj3((qD8!Xrx@6H-ZJp3@Ll5L8V8u0YRR=jzN(M z-mZ}fj-es`o_;`mzOH^D3V!}T9O~nvqo4$`QAwdJu_!qsu?WadDoRZSnt>2VOb5zC zjReXk7o{eaq^86tmMBf$$!E#N3-Z6fWe~hKMg=tEXiKV4wqDhizQnFEUiiM?# zS(+u#921~PMwUrt2BrpvAg#Iv7P^L(3Wmm329{Pv#(EYO#+Jq=xMe19vzOOKRc~Nm Mj6*$8W|4yc01Bp_X#fBK delta 308 zcmZp8z}T>Wae}lUD+2=q2*Uu=L>*&MRtCMIMZEk!7+CnE8ThUFxAIBzecCK2u$-5< zF@$;Y2ObkfmdUET3s_m$#G_3o_wq?he#EQA%v!-XnV(OOk!i9WpBIqqa1{%x( zGMpEP8To%R@c#xH^qyakfq|KkiQj+=RhXTDfrXi$(_m9T6n~6)lBs!`p>dK)qJ^cQ zp@CU)l98ENnx(n1QL<%XVoGvSYGP`NNs5_~fsv`MfrYN2k%FPQm5HU5frTDW$kf0T Yx6I^i@$%Xz>P?J|ai|B$EJ_dn0IBOi_5c6? From 29c04c3f5f2731d4f0ae41f7b81a600a6850cc49 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Tue, 19 Aug 2025 09:12:14 -0400 Subject: [PATCH 3/9] Set up initializer to pass tests --- app/models/puppy.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/models/puppy.rb b/app/models/puppy.rb index 77f6078..62c3e20 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 +class Puppy < ApplicationRecord + def self.new(name = nil, breed = nil, age = nil, **attrs) + if name && breed && age + super(attrs.merge(name: name, breed: breed, age: age)) + else + super + end + end end From 612624020e07f89de2e678c58f8c0d174e4be08a Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Tue, 19 Aug 2025 09:18:20 -0400 Subject: [PATCH 4/9] Set up routes and actions --- app/controllers/puppies_controller.rb | 14 ++++++++++---- config/routes.rb | 8 +++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/controllers/puppies_controller.rb b/app/controllers/puppies_controller.rb index ed1730d..f8d2904 100644 --- a/app/controllers/puppies_controller.rb +++ b/app/controllers/puppies_controller.rb @@ -1,6 +1,12 @@ 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 + end + + def new + @puppy = Puppy.new + end + + def create + @puppy = Puppy.create(params.permit(:name, :breed, :age)) + end end diff --git a/config/routes.rb b/config/routes.rb index 4c97056..361a6f8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,5 @@ 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 + get "/", to: "puppies#index" + get "/new", to: "puppies#new" + post "/puppy", to: "puppies#create" end From 8236c65a9d08a0bd87d861691cf32c3d45794553 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Tue, 19 Aug 2025 09:21:07 -0400 Subject: [PATCH 5/9] Render link to new puppy form --- app/views/puppies/index.html.erb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/app/views/puppies/index.html.erb b/app/views/puppies/index.html.erb index 2be4660..0a93d5b 100644 --- a/app/views/puppies/index.html.erb +++ b/app/views/puppies/index.html.erb @@ -1,10 +1,2 @@ - +

Welcome to the Puppy Adoption Site!

+<%= link_to "Click Here To List A Puppy", "/new" %> From 3f3f708b817328b05bec7de2aaa6b0cf25a0ce50 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Tue, 19 Aug 2025 09:33:36 -0400 Subject: [PATCH 6/9] Adjust to pass tests --- app/models/puppy.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/models/puppy.rb b/app/models/puppy.rb index 62c3e20..76d7726 100644 --- a/app/models/puppy.rb +++ b/app/models/puppy.rb @@ -1,9 +1,14 @@ -class Puppy < ApplicationRecord - def self.new(name = nil, breed = nil, age = nil, **attrs) - if name && breed && age - super(attrs.merge(name: name, breed: breed, age: age)) - else - super +class Puppy < ApplicationRecord + class << self + alias_method :ar_new, :new + + def new(*args, **attrs) + if args.size == 3 + name, breed, age = args + ar_new(attrs.merge(name: name, breed: breed, age: age)) + else + ar_new(*args, **attrs) + end end end end From 5cd15b9f6d8896e393eb905fa3170cfe696765d9 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Tue, 19 Aug 2025 09:38:41 -0400 Subject: [PATCH 7/9] Render new puppy form --- app/views/puppies/new.html.erb | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/views/puppies/new.html.erb b/app/views/puppies/new.html.erb index 45ca039..2eb378c 100644 --- a/app/views/puppies/new.html.erb +++ b/app/views/puppies/new.html.erb @@ -1,11 +1,20 @@ - +# Hint: Use form_with helper with url parameter +# --> +<%= form_with url: "/puppy", method: :post do |f| %> + <%= f.label :name %> + <%= f.text_field :name %> + <%= f.label :breed %> + <%= f.text_field :breed %> + <%= f.label :age %> + <%= f.text_field :age %> + <%= f.submit "submit" %> +<% end %> From 40ef8bb094183b7bdc08b86e196fd61b5b11c21c Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Tue, 19 Aug 2025 09:41:50 -0400 Subject: [PATCH 8/9] Display new puppy info --- app/views/puppies/create.html.erb | 24 +++++++++++++++--------- app/views/puppies/new.html.erb | 11 ----------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/app/views/puppies/create.html.erb b/app/views/puppies/create.html.erb index 6f54b98..10a5e3f 100644 --- a/app/views/puppies/create.html.erb +++ b/app/views/puppies/create.html.erb @@ -1,11 +1,17 @@ - +# Use the data passed from your controller action. +# Hint: Access the puppy data through instance variables from the controller +# --> + +
    +
  • Puppy Name: <%= @puppy.name %>
  • +
  • Puppy Breed: <%= @puppy.breed %>
  • +
  • Puppy Age: <%= @puppy.age %> months
  • +
diff --git a/app/views/puppies/new.html.erb b/app/views/puppies/new.html.erb index 2eb378c..f9f5e79 100644 --- a/app/views/puppies/new.html.erb +++ b/app/views/puppies/new.html.erb @@ -1,14 +1,3 @@ -# <%= form_with url: "/puppy", method: :post do |f| %> <%= f.label :name %> <%= f.text_field :name %> From d14af173cd3966b6a5036d68536fa6cd33091482 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Tue, 19 Aug 2025 09:42:04 -0400 Subject: [PATCH 9/9] Delete comments --- app/views/puppies/create.html.erb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/app/views/puppies/create.html.erb b/app/views/puppies/create.html.erb index 10a5e3f..e9c74fc 100644 --- a/app/views/puppies/create.html.erb +++ b/app/views/puppies/create.html.erb @@ -1,15 +1,3 @@ -# -
  • Puppy Name: <%= @puppy.name %>
  • Puppy Breed: <%= @puppy.breed %>