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
16 changes: 16 additions & 0 deletions app/controllers/puppies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,20 @@ class PuppiesController < ApplicationController
# 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!(puppy_params)
end

private

def puppy_params
params.permit(:name, :age, :breed)
end
end
10 changes: 1 addition & 9 deletions app/models/puppy.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
# 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
end
10 changes: 7 additions & 3 deletions app/views/puppies/create.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
TODO: Display the puppy information here!

Your view should display:
- Puppy Name: [name]
- Puppy Breed: [breed]
- Puppy Age: [age]
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
-->

<p>Puppy Name: <%= @puppy.name %></p>
<p>Puppy Breed: <%= @puppy.breed %></p>
<p>Puppy Age: <%= @puppy.age %> months</p>
2 changes: 2 additions & 0 deletions app/views/puppies/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@

Hint: Use Rails link_to helper
-->
<h1>Welcome to the Puppy Adoption Site!</h1>
<%= link_to 'Click Here To List A Puppy', new_path %>
10 changes: 10 additions & 0 deletions app/views/puppies/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@

Hint: Use form_with helper with url parameter
-->
<h1>Create a New Puppy</h1>
<%= form_with model: @puppy do |f|%>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :breed %>
<%= f.text_field :breed %>
<%= f.label :age %>
<%= f.number_field :age %>
<%= f.submit 'Create Puppy', id: 'submit' %>
<% end %>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
# - 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
root 'puppies#index'
get '/new', to: 'puppies#new'
post '/new', to: 'puppies#create'
end
11 changes: 11 additions & 0 deletions db/migrate/20250820143236_create_puppies.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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