Nice work. We added a controller and a route to the Rails app.
Why does the Messages controller use an action named
index? Check out the diagram in the browser. Rails provides seven standard controller actions for doing common operations with data. Here we want display a list of all messages, so we used the
Putting it all together:
- When a user visits
http://localhost:8000/messages, the routes file maps this request to the Messages controller's
index action retrieves all messages from the database and stores them in variable
@messages variable is passed on to the view. The view should display each message, so let's set it up next.