Review
Topics Covered: hashes, sinatra review
Exercises
Note: All exercises must live inside of your s0203_exercises/firstname_lastname/d4
folder
While inside of your s0203_exercises
directory, you can git add .
then git commit -m "Helpful commit message here"
and git push origin master
to submit your homework to GitHub. (Don't forget to use git status
along the way to check the state of your files in git)
Phone Book Sinatra App
Create a Sinatra App, phonebook_app
, that will list the contact info of some of your classmates.
In app.rb
, define 3 different routes:
a root '/'
- links to index view which gives you the option to see all contacts or a specific contact
a route to display all the contacts '/contacts'
- links to contacts view
- you will also need to define an array that has the names of 3 of your classmates and assign that to an instance variable
@contacts
a route to display a single contact '/contacts/:name'
.
- you will need to define a hash that maps the classmates names' from above to his or her phone number. Assign that hash to a variable
contacts
- think about what you want displayed in the contact view. You will probably want to assign those two pieces of information to instance variables so you can access them in the view. Think about how to use parameters in the route to display a specific person's contact information!
BONUS
- Add some CSS for fun! See Sinatra Docs for how-to.
- Keep your code DRY by integrating a layout view that links each page to your CSS file.