简体   繁体   English

Rails ActionController :: Metal实际上做了什么

[英]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.

相关问题 Rails 4 ActionController :: Metal与序列化器 - Rails 4 ActionController::Metal with Serializers Rails中的ActionController :: Base如何知道其模型是什么类? - How does ActionController::Base in Rails know what class its model is? "ActionController::Metal 需要什么模块才能将状态代码传递给渲染?" - What module is needed with ActionController::Metal to be able to pass status code to render? Rails:“渲染模板”实际意味着什么 - Rails: What does it actually mean to “render a template” 使用ActionController :: Metal设计验证 - Devise authentication with ActionController::Metal Rails:当不使用它返回的对象时,调用 ActionController::Parameters#permit() 会实现什么? - Rails: What does calling ActionController::Parameters#permit() achieve when not using the object returned by it? Ruby on Rails-什么-路由错误:未初始化的常量ActionController :: Responder-平均值,我该如何解决? - Ruby on Rails - What does - Routing Error: uninitialized constant ActionController::Responder - mean and how do I fix it? &#39;rails new -d&#39;(数据库预配置)切换实际上做了什么? - What does 'rails new -d' (preconfigure for database) switch actually do? ActionController :: InvalidAuthenticityToken(ActionController :: InvalidAuthenticityToken):Rails 5 - ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken): Rails 5 简化Rails项目的实际用途 - a simplification of what a rails project actually is
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM