diff --git a/app/controllers/puppies_controller.rb b/app/controllers/puppies_controller.rb index ed1730d..d73fd66 100644 --- a/app/controllers/puppies_controller.rb +++ b/app/controllers/puppies_controller.rb @@ -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 diff --git a/app/models/puppy.rb b/app/models/puppy.rb index 77f6078..1d94ec1 100644 --- a/app/models/puppy.rb +++ b/app/models/puppy.rb @@ -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 diff --git a/app/views/puppies/create.html.erb b/app/views/puppies/create.html.erb index 6f54b98..b25deb2 100644 --- a/app/views/puppies/create.html.erb +++ b/app/views/puppies/create.html.erb @@ -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 --> + +
Puppy Name: <%= @puppy.name %>
+Puppy Breed: <%= @puppy.breed %>
+Puppy Age: <%= @puppy.age %> months
diff --git a/app/views/puppies/index.html.erb b/app/views/puppies/index.html.erb index 2be4660..5ad23cc 100644 --- a/app/views/puppies/index.html.erb +++ b/app/views/puppies/index.html.erb @@ -8,3 +8,5 @@ Hint: Use Rails link_to helper --> +