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
29 changes: 22 additions & 7 deletions app/controllers/puppies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
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 redirect to show
# You'll need a 'show' action to display the puppy information
#
# Remember: After creating a puppy, you should redirect to the show page
def index
@puppies = Puppy.all
end

def show
@puppy = Puppy.find(params[:id])
end

def new
@puppy = Puppy.new
end

def create
puppy = Puppy.create!(puppy_params)
redirect_to puppy_path(puppy)
end

private

def puppy_params
params.require(:puppy).permit(:name, :breed, :age)
end
end
21 changes: 12 additions & 9 deletions app/views/puppies/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<!--
TODO: Create your homepage here!
<% if @puppies.empty? %>
<p>No puppies available yet. Be the first to add one!<p>
<% else %>
<h2>Available Puppies</h2>
<% @puppies.each do |puppy| %>
<div>
<%= "#{puppy.name} - #{puppy.breed} (#{puppy.age})" %>
<%= link_to "View Details", puppy_path(puppy) %>
</div>
<% end %>
<% end %>

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

Hint: Use Rails link_to helper with the new_puppy_path route helper
-->
<%= link_to "Click Here To List A Puppy", new_puppy_path %>
19 changes: 19 additions & 0 deletions app/views/puppies/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,22 @@
Hint: Use form_with helper with a model parameter instead of url parameter
This will automatically set the correct action and method
-->

<%= form_with model: @puppy, local: true do |form| %>
<%= form.label :name %>
<%= form.text_field :name %>

<br /><br />

<%= form.label :breed %>
<%= form.text_field :breed %>

<br /><br />

<%= form.label :age %>
<%= form.text_field :age %>

<br /><br />

<%= form.submit id: "submit" %>
<% end %>
14 changes: 3 additions & 11 deletions app/views/puppies/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
<!--
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 the @puppy instance variable from the controller
-->
<p>Puppy Name: <%= @puppy.name %></p>
<p>Puppy Breed: <%= @puppy.breed %></p>
<p>Puppy Age: <%= @puppy.age %></p>
5 changes: 1 addition & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
Rails.application.routes.draw do
# TODO: Add your routes here
# You need to use RESTful routing conventions
# Hint: Use the resources method to create all the standard RESTful routes
# This will create routes for index, show, new, create, edit, update, and destroy
resources :puppies, only: [:index, :show, :new, :create]
end