diff --git a/Gemfile b/Gemfile index 1a1b15d..293548c 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index caea9fb..b96a561 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4355099..09705d1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,2 @@ class ApplicationController < ActionController::Base - # protect_from_forgery with: :exception end diff --git a/app/controllers/puppies_controller.rb b/app/controllers/puppies_controller.rb index d682f57..6042fc2 100644 --- a/app/controllers/puppies_controller.rb +++ b/app/controllers/puppies_controller.rb @@ -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 diff --git a/app/models/puppy.rb b/app/models/puppy.rb index 1d94ec1..2dccd8c 100644 --- a/app/models/puppy.rb +++ b/app/models/puppy.rb @@ -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 diff --git a/app/views/puppies/index.html.erb b/app/views/puppies/index.html.erb index 237462e..730a64b 100644 --- a/app/views/puppies/index.html.erb +++ b/app/views/puppies/index.html.erb @@ -1,10 +1,4 @@ - +
<%= link_to "Click Here To List A Puppy", '/new' %>
+ diff --git a/app/views/puppies/new.html.erb b/app/views/puppies/new.html.erb index 7eacde8..2ef4b01 100644 --- a/app/views/puppies/new.html.erb +++ b/app/views/puppies/new.html.erb @@ -1,12 +1,19 @@ - +
+ <%= form.label :age %> + <%= form.text_field :age, id: "age"%> +
+ + <%= form.submit "submit" %> +<% end %> diff --git a/app/views/puppies/show.html.erb b/app/views/puppies/show.html.erb index b8ad62d..9a1540a 100644 --- a/app/views/puppies/show.html.erb +++ b/app/views/puppies/show.html.erb @@ -1,11 +1,6 @@ - +

+
+

Puppy Name: <%= @puppy[:name] %>

+

Puppy Breed: <%= @puppy[:breed] %>

+

Puppy Age: <%= @puppy[:age]%>

+
diff --git a/config/routes.rb b/config/routes.rb index 07741f6..727fe27 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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