What happens when you visit http://localhost:8000 in the browser? Check out the diagram in the browser.

  1. The browser makes a request for the URL http://localhost:8000.
  2. The request hits the Rails router in config/routes.rb. The router recognizes the URL and sends the request to the controller.
  3. The controller receives the request and processes it.
  4. The controller passes the request to the view.
  5. The view renders the page as HTML.
  6. The controller sends the HTML back to the browser for you to see.

This is called the request/response cycle. It’s a useful way to see how a Rails app’s files and folders fit together.



Looking at the request/response cycle, we need three parts to build a Rails app: a controller, a route, and a view. Let’s start here by creating a controller.

In the terminal, type:

rails generate controller Pages

After rails generate finishes running, in the Code Editor, open app/controllers/pages_controller.rb. Within the class PagesController, add a method home:

class PagesController < ApplicationController def home end end

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?