Your task is to write a RESTful routes & controllers for our Pizza Shop and fill in each with actual code. Earlier this week we had a skeleton, and now it's time to fill it out.
There are two important details to keep in mind. Tomorrow morning, we'll be demonstrating how to use HTML forms to send data from user input to our controller actions, which will be the final piece of the puzzle for creating a full blown web application.
- You don't have to create the controller actions for
new
andedit
. Skip those until tomorrow (unless you want to jump ahead on your own). - Hardcode your params for now. You'll need to specifically in your
create
andupdate
actions. We'll get those to be real data tomorrow.
#create
post "/pizzas" do
params = {name: "Red Anchovy Delight", sauce: 'red', cheese:true, mushrooms:true, extra_toppings: "anchoves"}
#...
- Definitely use
tux
to test out if your code works before placing inside your controller!! - Feel free to test out your routes with the
curl
command (uselocalhost:9292
as the url you'll hit).
In the last 10 minutes, we'll walk through a complete solution example so you can gauge how you did!
####Requirements
-
Write a RESTful controller for our pizza resource with
index
,show
,create
,update
, anddelete
routes. You should be using (but not limited to) the following ActiveRecord methods:.find
.all
.new
.save
.update_attributes
.destroy
-
Fill in each controller action with the CRUD operation that is appropriate for that action
-
Don't forget about
params
The same code as our lesson is included in the starter-code
folder. The Sinatra setup is ready to go, you just need to fill in your controller.
Shoot to create a complete RESTful controller with appropriate ActiveRecord methods inside and compare your work with the solution code when complete.
You'll get a lot more practice with this so don't sweat it if you're struggling, but if you are:
- Don't freeze up, try things out
- Read all errors carefully
- Identify your knowledge gaps
- Formulate a question
- ASK THAT QUESTION!
###Resources