Skip to content

Instantly share code, notes, and snippets.

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

#Sinatra: Part 2

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 the static assets (stylesheets, javascripts, and images) from the student static website.

  • Style the students index page

Add your static assets

if you need assets! 003.students.flatironschool.com

In Sinatra, static files are served from the ./public directory. You can specify a different location by setting the :public_folder option:

set :public_folder, File.dirname(__FILE__) + '/static'

Note that the public directory name is not included in the URL. A file ./public/css/style.css is made available as http://example.com/css/style.css.

http://www.sinatrarb.com/intro.html#Static%20Files

  1. Create a directory called 'public' in the root of the project.

  2. Copy your static assets such as css, javascript, and images over to this folder.

Style the students listing

In part one, you created an ERB template to output your listing of all the students. Now your goal is to apply the HTML markup you created to your new students layout. You should use that markup and combine it with the block you made to output all the students data. Remember that the ERB extension renders to HTML, so HTML in your .erb templates is perfectly fine.

Instead of having each students information hardcoded, you will now use Ruby and ERB in your layout to loop through each student and output the appropriate markup and information from the database.

For example, if I had an array of artists I could do something like:

<% @artists.each do |artist| %>
  <h1><%= artist.name %></h1>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment