Request-Response Cycle III
When developing a Rails app, the request/response cycle is a useful guide to trace how a user’s request flows through the app. A common category of web apps that are built with Ruby on Rails are form-based apps. These kinds of apps give users a form for submitting data, stores that data in a database, and lets users view or modify those entries. Here’s how a user’s request flows through a form-based app.
Turn 1
In the first turn of the request/response cycle, the page with the form is displayed to the user.
- A user opens his browser, types in a URL, and presses Enter.
- When the user presses Enter, the browser sends a
GET
request for that URL. - The
GET
request hits the Rails router (config/routes.rb). The router maps the URL to the correct controller action to handle the request. - The action receives the
GET
request and passes it on to the view. - The view renders the page as HTML.
- The controller sends the HTML back to the browser. The page loads and the user sees the page with the form.
Learn Ruby on Rails
Learn the basics of building applications with this convenient and powerful web development framework.Try it for freeTurn 2
When a user submits the form, it triggers the second turn of the request/response cycle, where the submitted data is saved into the database.
- The user fills in the form and submits the form.
- When the user submits the form, the browser sends a
POST
request to the Rails app. - The
POST
request hits the Rails router. The router maps thePOST
request to the correct controller action. - The action receives the
POST
request. The action retrieves the submitted data from the form, and uses the model to store the data into the database. - The model completes its task.
- The controller action passes the request on to the view.
- The view renders the page as HTML.
- The controller sends the HTML back to the browser. The page loads and the user sees it.
'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'
Meet the full teamRelated articles
- Article
Request-Response Cycle II
Guide for navigating a dynamic Rails app. - Article
Request-Response Cycle I
Guide for navigating a Rails app with static pages. - Article
Back-End Web Architecture
This article provides an overview of servers, databases, routing, and anything else that happens between when a client makes a request and receives a response.
Learn more on Codecademy
- Course
Learn Ruby on Rails
Learn the basics of building applications with this convenient and powerful web development framework.With CertificateIntermediate6 hours - Free course
Learn HTML: Forms
Learn how to create HTML forms with various input fields to collect and validate user data.Beginner Friendly2 hours - Free course
OWASP Top 10: Server Side Request Forgery
You will learn about Server-Side Request Forgery, what it is and how to prevent it.Intermediate< 1 hour