diff --git a/app/controllers/puppies_controller.rb b/app/controllers/puppies_controller.rb index ed1730d..222a7c6 100644 --- a/app/controllers/puppies_controller.rb +++ b/app/controllers/puppies_controller.rb @@ -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 diff --git a/app/models/puppy.rb b/app/models/puppy.rb index 77f6078..d324ddc 100644 --- a/app/models/puppy.rb +++ b/app/models/puppy.rb @@ -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 diff --git a/app/views/puppies/create.html.erb b/app/views/puppies/create.html.erb index 6f54b98..bc1d9c4 100644 --- a/app/views/puppies/create.html.erb +++ b/app/views/puppies/create.html.erb @@ -1,11 +1,7 @@ - +
+ +
diff --git a/app/views/puppies/index.html.erb b/app/views/puppies/index.html.erb index 2be4660..a633b00 100644 --- a/app/views/puppies/index.html.erb +++ b/app/views/puppies/index.html.erb @@ -1,10 +1,3 @@ - +<%= link_to "Click Here To List A Puppy", new_path %> diff --git a/app/views/puppies/new.html.erb b/app/views/puppies/new.html.erb index 45ca039..cd4db5c 100644 --- a/app/views/puppies/new.html.erb +++ b/app/views/puppies/new.html.erb @@ -1,11 +1,23 @@ - +
+ <%= f.label :name %> + <%= f.text_field :name %> +
+ +
+ <%= f.label :breed %> + <%= f.text_field :breed %> +
+ +
+ <%= f.label :age %> + <%= f.number_field :age %> +
+ +
+ <%= submit_tag "submit" %> +
+<% end %> diff --git a/config/routes.rb b/config/routes.rb index 4c97056..00a6fb6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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