ruby rails web 请求响应生命周期 [英] ruby rails web request response lifecycle

查看:63
本文介绍了ruby rails web 请求响应生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 ruby​​ on rails 新手,试图深入了解 ruby​​ on rails 网络应用程序中典型请求/响应生命周期的流程.

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.

我在谷歌上搜索了相关信息,但没有找到完整或详细到 DNS 服务器级别到调度员的答案.

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.

我最接近一个好的解释是:http://brainspl.at/request_response.pdf.

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

推荐答案

所以您要求使用 rails 请求/响应周期,并且您已经参考了一个演示文稿,它确实很好地描述了它.所以我假设你想从一个非常高的层次上了解它,并且你完全需要这个概念来进行开发.然后就是这里了.我只是想按顺序命名这些部分.

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. 路线:在这里,您将绘制世界访问您的应用程序将使用的路径.使用完整的 RESTful 架构,您需要定义资源的层次结构并定义如何访问资源以执行某些操作.如果对您的应用程序的任何请求与路由文件中的任何路径都不匹配,则不会对其进行处理.如果发生任何匹配,它将找到相应的控制器和动作并调用它.在调用的时候,它会将所有请求相关的数据存储在params hash中.
  2. 过滤器之前: 现在您的应用程序已经知道哪个控制器#method 将处理请求.它会在调用该方法之前检查是否有任何配置要执行.这是通过使用 before_filter 来完成的.如果找到任何内容,则将首先调用这些函数.
  3. 方法执行:在按特定顺序执行所有before_filter 方法后,它将调用实际方法.在此方法中,所有数据都在 params 散列中可用.它处理输入数据,调用模型调用以访问数据库,并准备数据以供查看.
  4. 视图:将根据 controller#action 格式选择正确的视图文件.或者您可以通过 render :partial 调用选择要渲染的任何特定视图.并且将使用控制器中准备的变量准备响应.此响应将发送给客户端.
  5. 过滤器后:处理完视图后,它将查找 after_filter 方法,如果找到,将查找.
  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.

好吧,我会说这是一个快速概述,没有任何细节.我再说一遍,你提到的pdf确实包含更多细节.

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.

这篇关于ruby rails web 请求响应生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆