我想了解Rails ActionController :: Metal控制器.我在这里已经读到了它,但完全不理解它.
它用于构建API,但我们也可以在没有它的情况下构建API.
那它究竟做了什么,它有多大用处?
可以请任何人用例子解释它吗?
and*_*scu 24
ActionController :: Metal本质上是ActionController :: Base的精简版本.它主要用于API,因为它不包含通常带有Rails控制器的模块,从而提高了性能(甚至40%,具体取决于用例https://gist.github.com/drogus/738168).
鉴于它只包含最基本的控制器功能,您只需为自己的类添加所需的功能.例如,可以添加渲染,令牌身份验证和过滤功能:
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
Run Code Online (Sandbox Code Playgroud)
它基本上是一种确保您充分利用计算资源的快速方法.
| 归档时间: |
|
| 查看次数: |
3227 次 |
| 最近记录: |