Listing The Jobs

What we're going to do

  • Show the jobs!
  • Learn about ERB

Going back to the jobs index (http://localhost:3000/jobs), we expect to see the new jobs. Let's actually build the job board part of this job board now!

Get all the jobs out of the database

If we're going to show our jobs in view, first we have to get them out of the database and store them in an instance variable. Update the index method to look like this:

def index
  @jobs = Job.all
end

Before we show the jobs, let's actually look at what that is doing. Go back to your Rails console and run Job.all.

Discussion: Rails Console


The Rails console is super fun! It's giving us direct access to our local database.

  • Try running Job.all.to_sql. What does that do?
  • Try selecting an individual Job record.
  • Try updating an that individual record from the console!

Show those jobs!

Add this to app/views/jobs/index.html.erb:

<% @jobs.each do |job| %>
  <h3><%= job.title %></h3>
  <p><%= job.description %></p>
<% end %>

Discussion: ERB


What is this doing? Go through this line by line, having one person explain each line.

Compare the ERB to the HTML that shows up on the page. ("Inspect Element" is your friend!)

What's the difference between a line with <% %> brackets and <%= %> brackets?

Next Step: