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
18 changes: 14 additions & 4 deletions app/controllers/puppies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
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.new(
name: params[:name],
breed: params[:breed],
age: params[:age]
)
end
end
15 changes: 7 additions & 8 deletions app/models/puppy.rb
Original file line number Diff line number Diff line change
@@ -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: nil, breed: nil, age: nil)
@name = name
@breed = breed
@age = age
end
end
18 changes: 7 additions & 11 deletions app/views/puppies/create.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<!--
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
-->
<div>
<ul>
<li>Puppy Name: <%= @puppy.name %> </li>
<li>Puppy Breed: <%= @puppy.breed %> </li>
<li>Puppy Age: <%= @puppy.age %> </li>
</ul>
</div>
11 changes: 2 additions & 9 deletions app/views/puppies/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
<!--
TODO: Create your homepage here!
<h1>Welcome to the Puppy Adoption Site</h1>

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
-->
<%= link_to "Click Here To List A Puppy", new_path %>
30 changes: 21 additions & 9 deletions app/views/puppies/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
<!--
TODO: Create your form here!
<h3>New Puppy Form</h3>

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"
<%= form_with url: "/puppy", local: true do |f| %>

Hint: Use form_with helper with url parameter
-->
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>

<div class="field">
<%= f.label :breed %>
<%= f.text_field :breed %>
</div>

<div class="field">
<%= f.label :age %>
<%= f.number_field :age %>
</div>

<div class="actions">
<%= submit_tag "submit" %>
</div>
<% 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