The ":nothing" option is deprecated and will be removed in Rails 5.1

Ruby on-RailsRuby on-Rails-5

Ruby on-Rails Problem Overview


This code in rails 5

class PagesController < ApplicationController
  def action
    render nothing: true
  end
end

results in the following deprecation warning

DEPRECATION WARNING: :nothing` option is deprecated and will be removed in Rails 5.1. Use `head` method to respond with empty response body.

How do I fix this?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

According to the rails source, this is done under the hood when passing nothing: true in rails 5.

if options.delete(:nothing)
  ActiveSupport::Deprecation.warn("`:nothing` option is deprecated and will be removed in Rails 5.1. Use `head` method to respond with empty response body.")
  options[:body] = nil
end

Just replacing nothing: true with body: nil should therefore solve the problem.

class PagesController < ApplicationController
  def action
    render body: nil
  end
end

alternatively you can use head :ok

class PagesController < ApplicationController
  def action
    head :ok
  end
end

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLinus OleanderView Question on Stackoverflow
Solution 1 - Ruby on-RailsLinus OleanderView Answer on Stackoverflow