Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby rails web request response lifecycle

I'm a novice in ruby on rails trying to understand the in-depth flow of a typical request/response life cycle in ruby on rails web application.

I have googled for the info and have not found an answer which is complete or detailed to the level of DNS servers to dispatchers.

The closest I got to a good explanation is at: http://brainspl.at/request_response.pdf.

Can someone point me to a better or more detailed explanation?

-Raviteja

like image 548
Raviteja Adusumalli Avatar asked Dec 07 '22 11:12

Raviteja Adusumalli


2 Answers

So you are asking for rails request/response cycle and you already referred to a presentation which really describes it very well. So im assuming that you want to know it from a very high level and you need this concept totally for development. Then here it is. Im just trying to name the parts sequentially.

  1. Route: Here you will draw the paths which will be used by the world to access your application. With a complete RESTful architecture, you need to define the hierarchy of your resources and define how a resource can be accessed to perform some action. If any request to your application doesnt match with any path in the routes file, it will not be processed. If any match occurs, it will find the corresponding controller and action and will call it. At the time of calling, it will store all the request related data in params hash.
  2. Before Filters: Now your application already know which controller#method is gonna process the request. And it will check if there is anything configured to execute before calling that method. This is done by using before_filter. If found anything then those functions will be called first.
  3. Method Execution: After executing all the before_filter methods in a particular sequence, it will call the actual method. All the data is available in params hash in this method. It processes input data, invokes Model calls for database access, and prepare data for view.
  4. View: Proper view file will be chosen based on the controller#action, format. Or you might select any particular view to render by render :partial call. And the response will be prepared using the variables prepared in controller. This response will go to the client.
  5. After Filters: After processing the view, it will look after_filter methods and will those if found.

Well this was a quick overview i would say, without really any details. Im saying again, the pdf you referred really contains more details.

Let me know if you want to know anything more specifically.

like image 66
Samiron Avatar answered Dec 18 '22 21:12

Samiron


A user opens his browser, types in a URL, and presses Enter. When a user presses Enter, the browser makes a request for that URL. The request hits the Rails router (config/routes.rb). The router maps the URL to the correct controller and action to handle the request. The action receives the request, and asks the model to fetch data from the database. The model returns a list of data to the controller action. The controller action passes the data 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.

https://www.codecademy.com/articles/request-response-cycle-dynamic and https://www.codecademy.com/articles/request-response-cycle-forms

like image 28
Melissa Quintero Avatar answered Dec 18 '22 20:12

Melissa Quintero