Rails ActionController::Metal 究竟做了什么 [英] What actually does Rails ActionController::Metal

查看:32
本文介绍了Rails ActionController::Metal 究竟做了什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解 Rails ActionController::Metal 控制器.我已经在此处阅读了相关内容,但并不完全理解.

I want to understand about Rails ActionController::Metal controller. I have read about it here but don't understand it completely.

它用于构建 API,但我们也可以在没有它的情况下构建 API.

It is used to build API's but we can build API's without it as well.

那么它到底有什么作用,有多大用处?

So what does it exactly do and how much is it useful?

谁能用例子解释一下?

推荐答案

ActionController::Metal 本质上是 ActionController::Base 的精简版.它主要用于 API,因为它不包含通常带有 Rails 控制器的模块,从而提高了性能(甚至 40%,取决于用例 https://gist.github.com/drogus/738168).

ActionController::Metal is essentially a stripped down version of 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).

鉴于它仅包含最基本的控制器功能,因此您只能为自己的类添加所需的功能.例如,可以添加渲染、令牌身份验证和过滤功能:

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.

这篇关于Rails ActionController::Metal 究竟做了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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