- Read Tutorial
- Watch Guide Video
In this lesson, we are going to understand routes. If you're new to programming, routes are essentially what the application needs to move from page to page, and the requests it sends to do it.
Broadly speaking, there is a front-end and a backend to every application. The front-end is your browser and includes everything that gets displayed here, while the backend is where all the processing takes place to display appropriate data in the front-end.
To get a brief introduction of routing in Rails, let's start the server.
rails s
Now, if I go to the browser and type localhost:3000/projects
this will open my projects
page. This URL is the route. When I type this route, the browser sends a request to the database, and in turn, the database responds by sending all the records present in it. The browser renders all this data in a format specified by the user, or in this case, the format pre-determined by Rails.
When I do something on this page like clicking on New
, the browser takes me to a different page, which is localhost:3000/projects/new
If I enter the title and description and click on create, the browser goes to the page localhost:3000/projects/13
. So, the browser sends a request, gets it from the database, renders it on the page and moves to the next page based on the logic written in the code.
In the next lesson, we'll talk about how you can configure routes yourself.