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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem 'fiddle'
gem 'logger'
gem 'mutex_m'
gem 'ostruct'
gem 'pry'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.3', '>= 6.1.3.1'
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
coderay (1.1.3)
concurrent-ruby (1.3.5)
crass (1.0.6)
date (3.4.1)
Expand Down Expand Up @@ -131,6 +132,9 @@ GEM
ast (~> 2.4.1)
racc
prism (1.4.0)
pry (0.15.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (6.0.2)
puma (5.6.9)
nio4r (~> 2.0)
Expand Down Expand Up @@ -253,6 +257,7 @@ DEPENDENCIES
mutex_m
nio4r (~> 2.7)
ostruct
pry
puma (~> 5.0)
rack-cors
rails (~> 6.1.3, >= 6.1.3.1)
Expand Down
1 change: 0 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
class ApplicationController < ActionController::Base
# protect_from_forgery with: :exception
end
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 new
@puppy = Puppy.new
end

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

def create
@puppy = Puppy.create(puppy_params)
render :show
end

private

def puppy_params
params.require(:puppy).permit(:name, :breed, :age)
end
end
8 changes: 8 additions & 0 deletions app/models/puppy.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# 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
def to_s
name + ' ' + breed + ' ' + age
end
end
12 changes: 3 additions & 9 deletions app/views/puppies/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<!--
TODO: Create your homepage here!
<h1>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 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
-->
<div><%= link_to "Click Here To List A Puppy", '/new' %></div>
</div>
27 changes: 17 additions & 10 deletions app/views/puppies/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<!--
TODO: Create your form here!
<h1>Puppy Form</h1>
<%= form_with model: @puppy, url: puppies_path, local: true do |form| %>
<div>
<%= form.label :name %>
<%= form.text_field :name, id: "name" %>
</div>

Your form should:
- Use Rails form helpers (form_with)
- Submit to the puppies_path (POST /puppies)
- Have fields for: name, breed, age
- Have a submit button with "submit" text and type="submit"
<div>
<%= form.label :breed %>
<%= form.text_field :breed, id: "breed"%>
</div>

Hint: Use form_with helper with a model parameter instead of url parameter
This will automatically set the correct action and method
-->
<div>
<%= form.label :age %>
<%= form.text_field :age, id: "age"%>
</div>

<%= form.submit "submit" %>
<% end %>
17 changes: 6 additions & 11 deletions app/views/puppies/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<!--
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
-->
<h1></h1>
<div>
<p>Puppy Name: <%= @puppy[:name] %></p>
<p>Puppy Breed: <%= @puppy[:breed] %></p>
<p>Puppy Age: <%= @puppy[:age]%></p>
</div>
6 changes: 2 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
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: %i[show new create]
get '/', to: 'puppies#index'
end