#150 Rails Metal (revised)
Jan 27, 2012 | 6 minutes | Rack
Rails metal may have been removed in Rails 3, but it is possible to bypass the entire Rails stack through middleware as shown in this episode.
- source codeProject Files in Zip (81.1 KB)
- mp4Full Size H.264 Video (13.9 MB)
- m4vSmaller H.264 Video (7.64 MB)
- webmFull Size VP8 Video (9.06 MB)
- ogvFull Size Theora Video (17.9 MB)
Great idea and well presented as usual Ryan...
Title was a little misleading though :/
I am trying to avoid renaming the titles of the episodes when I revise them, so I understand that can make it a little misleading.
Understood - would be good to see more on Metal though :)
Particularly, the common pitfalls when trying to include behaviour that may be strewn across two or three ActionController modules
We'd probably see a more significant improvement in performance if your action wasn't shelling out. eg. if you just ran some ruby code or returned the contents of a file instead of starting a sub-shell to get the process list.
Thanks for the screencast!
If we add a few middle on the top of the stack and gain performance for those items, will it slow down the rest of the app because the middleware stack is now deeper?
It depends on what you're doing in the middleware, but usually it will only add a quick "if" condition and a couple method calls to the stack. In theory it is slightly slower but nothing that will be noticeably slower.
ActionController::Metal is basically a stripped down rendition of ActionController::Base. It's chiefly utilized for API's on account of it does exclude modules that regularly accompany a Rails controller, in this way enhancing execution.
To get this working in Rails 5, I had to turn off Turbolinks. Checkout the source code on how to get this working in Rails 5.