Saving Data


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 index action.

Putting it all together:

  1. When a user visits http://localhost:8000/messages, the routes file maps this request to the Messages controller's index action.
  2. The index action retrieves all messages from the database and stores them in variable @messages.

The @messages variable is passed on to the view. The view should display each message, so let's set it up next.


Now that we have a model, controller, and route, let's move on to the fourth part of the request/response cycle and create a view.

Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.