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

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?


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