DEV Community

Cover image for Request/Response Cycle
Evelyn Hernandez
Evelyn Hernandez

Posted on

Request/Response Cycle

A common category of web applications built with RoR are form-based apps, which give users a form for submitting data, which stores that data in a database and lets users view or modify those entries.

Displaying the form to the user

  1. A user enters a URL path on their browser and executes.
  2. When the URL path is executed, the browser sends a GET request for that URL.
  3. The GET request hits the rails router (config/routes.rb). The router maps the URL to a controller action to handle the request.
  4. The controller action receives the GET request and passes it on to the view.
  5. The view renders the page as HTML.
  6. The controller sends the HTML back to the browser. The page loads and the user sees the page with the form.

Submitting the form

  1. The user fills and submits the form.
  2. When the form is submitted, the browser sends a POST request to the Rails app.
  3. The POST request hits the rails router(config/routes.rb). The router maps the POST request to the correct controller action.
  4. The controller action receives the POST request. The controller action retrieves the submitted data from the form and uses the model to store the data into the database.
  5. The model completes its task.
  6. The controller action passes the request on to the view.
  7. The view renders the page as HTML.
  8. The controller sends the HTML back to the browser. The page loads and the user sees it.

Top comments (0)