简体   繁体   English

ActionPack和Rack有什么区别? (导轨)

[英]What is the difference between ActionPack and Rack? (Rails)

I'm trying to gain a deeper understanding of the Ruby on Rails framework and I've been doing a lot of googling about terms I've heard thrown around but never understood. 我试图对Ruby on Rails框架有更深入的了解,并且我一直在搜寻很多我听说过但从未理解过的术语。

Two of these terms were "ActionPack" and "Rack" 其中两个术语是“ ActionPack”和“ Rack”

According to the docs for each of these: 根据这些文档中的每一个:

ActionPack: ActionPack的:

Action Pack is a framework for handling and responding to web requests. Action Pack是用于处理和响应Web请求的框架。 It provides mechanisms for routing (mapping request URLs to actions), defining controllers that implement actions, and generating responses by rendering views, which are templates of various formats. 它提供了路由机制(将请求URL映射到动作),定义实现动作的控制器以及通过渲染视图(各种格式的模板)生成响应的机制。 In short, Action Pack provides the view and controller layers in the MVC paradigm. 简而言之,Action Pack在MVC范例中提供了视图和控制器层。

Rack: 架:

Rack provides a minimal interface between webservers that support Ruby and Ruby frameworks. Rack在支持Ruby和Ruby框架的Web服务器之间提供了最小的接口。

From the googling I've been doing, I've put the following model together in my head, but I'm still a bit unsure: 从我一直在使用谷歌搜索功能,我已经将以下模型放在脑海中了,但我仍然不确定:

If I understand correctly, Rack is more of a specification/standard for what an application/program should accept as input/produce as output (a program that does this being considered "rack compatible"). 如果我理解正确,那么Rack更像是一个规范/标准,用于说明应用程序/程序应接受什么作为输入/产生为输出(执行此操作的程序被视为“机架兼容”)。 ActionPack is a the program rails uses to do this. ActionPack是Rails用来执行此操作的程序。 So the request would go: Client HTTP request --> Server --> ActionPack --> The Rest of Rails etc. 因此请求将发送: Client HTTP request --> Server --> ActionPack --> The Rest of Rails etc.

Is this correct? 这个对吗? Or have I misunderstood? 还是我误会了?

Many other frameworks can be Rack-based applications, such as Sinatra or Grape . 许多其他框架可以是基于Rack的应用程序,例如SinatraGrape

To use Rack, provide an "app": an object that responds to the call method, taking the environment hash as a parameter, and returning an Array with three elements: 要使用Rack,请提供一个“ app”:一个对象,该对象响应call方法,将环境哈希作为参数,并返回包含三个元素的Array:

The HTTP response code HTTP响应代码

A Hash of headers 标头哈希

The response body, which must respond to each 响应主体,必须对每个响应

That means: with rack you can interact with web requests directly, permitting the community to build different tools or frameworks that are based on that simple rule of interaction. 这意味着:利用机架,您可以直接与Web请求进行交互,从而允许社区根据该简单的交互规则构建不同的工具或框架。 The app object in question IS the framework. 有问题的app对象是框架。

ActionPack is Rails' part that is interacting with Rack, it consists of a combination of ActionController and ActionView which makes our marvelous MVC architecture be as it is. ActionPack是Rails与Rack交互的一部分,它由ActionControllerActionView的组合组成,这使我们出色的MVC体系结构保持原样。 Check this answer for a detailed view on ActionPack 检查此答案以获取有关ActionPack的详细视图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM