Skip to content

Instantly share code, notes, and snippets.

@ashleygwilliams
Last active December 18, 2015 22:18
Show Gist options
  • Save ashleygwilliams/5853058 to your computer and use it in GitHub Desktop.
Save ashleygwilliams/5853058 to your computer and use it in GitHub Desktop.
part 3

#Sinatra: Part 3

Objectives

Continue re-creating the student website as a dynamic web application using Sinatra and the Student Class you created in the Student Class DB lab.

  • Add a route/controller for the students individual profile pages.

  • Add the ERB template for the students individual profile pages.

  • Link the students to their profile pages

Adding a route for the students individual profile pages.

Using what you've learned about Sinatra thus far, construct a single route that will return any one student from the database. This one route should work for any student, so that if you wanted to retrieve the view displaying information about Avi, you would utilize the same route as you would if you wanted to get the view displaying information about Jon. In other words, don't create a unique route for each student, but make one that includes a named parameter and use that paramater to look up the requested student in the database.

Reference: http://www.sinatrarb.com/intro.html#Routes

Add the ERB template for the students individual profile pages.

In the views directory, create an ERB template for individual student profiles and apply the styling to it. You'll want to pass this a student instance and populate the fields with ERB tags. Remember, this one template should work for any student, so test it with all of them to make sure you catch any bugs.

Link the students to their profile pages

Back on the student index view, add a link so that when you click on a students name or photo, you are redirected to their individual profile page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment