[英]What actually does Rails ActionController::Metal
I want to understand about Rails ActionController::Metal controller. 我想了解Rails ActionController :: Metal控制器。 I have read about it here but don't understand it completely.
我在这里已经读到了它,但完全不理解它。
It is used to build API's but we can build API's without it as well. 它用于构建API,但我们也可以在没有它的情况下构建API。
So what does it exactly do and how much is it useful? 那它究竟做了什么,它有多大用处?
Can please anyone explain it with examples? 可以请任何人用例子解释它吗?
ActionController::Metal is essentially a stripped down version of ActionController::Base. ActionController :: Metal本质上是ActionController :: Base的精简版本。 It's mainly used for API's because it doesn't include modules that typically come with a Rails controller, thus improving performance (even 40%, depending on the use case https://gist.github.com/drogus/738168 ).
它主要用于API,因为它不包含通常带有Rails控制器的模块,从而提高了性能(甚至40%,具体取决于用例https://gist.github.com/drogus/738168 )。
Given the fact that it only includes the most basic controller functionality allows you to only add the needed features for your own classes. 鉴于它只包含最基本的控制器功能,您只需为自己的类添加所需的功能。 For example, one can add rendering, token auth and filtering functionality:
例如,可以添加渲染,令牌身份验证和过滤功能:
class ApiGenericController < ActionController::Metal
include ActionController::Rendering
include ActionController::Renderers::All
include ActionController::MimeResponds
include ActionController::ImplicitRender
include AbstractController::Callbacks
include ActionController::HttpAuthentication::Token::ControllerMethods
It's basically a quick method to ensure that you make best use of your compute resources. 它基本上是一种确保您充分利用计算资源的快速方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.