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/app/models/puppy.rb b/app/models/puppy.rb index 77f6078..76d7726 100644 --- a/app/models/puppy.rb +++ b/app/models/puppy.rb @@ -1,10 +1,14 @@ -# 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 < ApplicationRecord + class << self + alias_method :ar_new, :new -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 + 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 diff --git a/app/views/puppies/create.html.erb b/app/views/puppies/create.html.erb index 6f54b98..e9c74fc 100644 --- a/app/views/puppies/create.html.erb +++ b/app/views/puppies/create.html.erb @@ -1,11 +1,5 @@ - + 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" %> diff --git a/app/views/puppies/new.html.erb b/app/views/puppies/new.html.erb index 45ca039..f9f5e79 100644 --- a/app/views/puppies/new.html.erb +++ b/app/views/puppies/new.html.erb @@ -1,11 +1,9 @@ - +<%= 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 %> 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 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 9fb98b5..cba197d 100644 Binary files a/db/test.sqlite3 and b/db/test.sqlite3 differ 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