简体   繁体   中英

What actually does Rails ActionController::Metal

I want to understand about Rails ActionController::Metal controller. 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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM