Render nothing is deprecated in Ruby on Rails 5. As Kevin explains in the video, when you render nothing, Rails still sends an HTML header and a success status code even though it is not obvious that it would. Instead, to make it clearer, developers should use head(:ok), or head with another status code, to make it clearer what is actually happening. Render nothing will still work in Rails 5, but it gives deprecation warnings, and will likely disappear in Rails 5.1.
- [Voiceover] Another change in Ruby on Rails five…is that render nothing has been deprecated.…Here's what I'm talking about.…It was possible before in your controller…to simply render nothing at times.…So, for example, if we have an authorized user…we would render a page to them,…but otherwise, we might render nothing.…We did that with render nothing true.…When you do it this way,…it's not actually rendering nothing.…It's still sending an html header with the status code…letting the browser know that the request…was answered successfully.…
That's the effect that we probably want,…but it isn't entirely clear from what you see…in the code that that's what's happening.…And therefore, it's been decided that…it's much better to use the head method,…which returns an html header with whatever…status code or options that you set,…but which has an empty body.…They do the same thing,…but the second one makes it clear what's happening.…For this reason, using render nothing true…in Rails five will still work,…but you'll also get a deprecation warning…
Released
5/4/2016- Using ActionCable to work with WebSockets
- Rendering templates independently of controllers
- Creating JSON API applications
- Using Turbolinks for faster page loads
- Working with new ActiveRecord features
- Leveraging improvements to date and time, parameters, and more
- Understanding deprecations and deletions
Share this video
Embed this video
Video: Deprecated render nothing