加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 21:48:23 所属栏目:百科 来源:网络整理
导读:我想了解Rails ActionController ::金属控制器.我已经阅读了 here,但不完全明白. 它用于构建API,但是也可以构建API. 那么它究竟做了什么,它有多少有用? 有人可以用例子来解释吗? 解决方法 ActionController :: Metal本质上是一个被删除的ActionController
我想了解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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读