ruby-on-rails – 实际上是什么Rails ActionController :: Metal

我想了解Rails ActionController ::金属控制器.我已经阅读了 here,但不完全明白.

它用于构建API,但是也可以构建API.

那么它究竟做了什么,它有多少有用?

有人可以用例子来解释吗?

解决方法

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

这基本上是一个快速方法,以确保您最好地利用您的计算资源.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...