Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions app/controllers/puppies_controller.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 12 additions & 8 deletions app/models/puppy.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 5 additions & 11 deletions app/views/puppies/create.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<!--
TODO: Display the puppy information here!

Your view should display:
- Puppy Name: [name]
- Puppy Breed: [breed]
- Puppy Age: [age]

Use the data passed from your controller action.
Hint: Access the puppy data through instance variables from the controller
-->
<ul>
<li>Puppy Name: <%= @puppy.name %></li>
<li>Puppy Breed: <%= @puppy.breed %></li>
<li>Puppy Age: <%= @puppy.age %> months</li>
</ul>
12 changes: 2 additions & 10 deletions app/views/puppies/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
<!--
TODO: Create your homepage here!

This page should:
- Welcome visitors to the Puppy Adoption Site
- Include a link to the new puppy form
- The link should go to '/new' and should have the text "Click Here To List A Puppy"

Hint: Use Rails link_to helper
-->
<h1>Welcome to the Puppy Adoption Site!</h1>
<%= link_to "Click Here To List A Puppy", "/new" %>
20 changes: 9 additions & 11 deletions app/views/puppies/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<!--
TODO: Create your form here!

Your form should:
- Use Rails form helpers (form_with)
- Submit to '/puppy' with POST method
- Have fields for: name, breed, age
- Have a submit button with "submit" text and type="submit"

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 %>
8 changes: 3 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions db/migrate/20250819130857_create_puppies.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file modified db/test.sqlite3
Binary file not shown.
10 changes: 0 additions & 10 deletions models/puppy.rb

This file was deleted.