- Draw a get route
- Map a route to a controller action
- Define a controller action
- Load instances from ActiveRecord into a controller instance variable
- Render a template
- Use an instance variable from a controller action in a template
- Iterate over an ActiveRecord collection in ERB
- Build a classical index action/view
In this lab you will walk through how to build each element required to render a
list of students out in the browser. The RSpec/Capybara tests for this lab can
be found in spec/features
. Both tests should be passing to complete the lab.
-
Run
bundle install
from your terminal -
Create a controller for students and have it inherit from ApplicationController
-
Create a route for the path
/students
that maps to a StudentsControllerindex
action. -
Add a controller action to the StudentsController named
index
-
Have the new
index
action pull in a list of all of the students withStudent.all
and store it in an instance variable -
Create an
index.html.erb
view file and render it from yourStudents#index
action. Theindex.html.erb
file should be placed within aviews/students
folder. -
In your view, iterate over the list of students returned from the index action in the controller and display the appropriate information.
- If you run into an ActiveRecord::PendingMigration error when you run the
tests, try
rake db:migrate RAILS_ENV=test
in the terminal then run the tests again