119

Rails 5のこのコード

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

次の非推奨警告が表示されます

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

これを修正するにはどうすればよいですか?

4

1 に答える 1

191

Rails sourceによると、これはnothing: trueRails 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

したがって、に置き換えるだけで問題が解決するはずですnothing: truebody: nil

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

代わりに使用できます head :ok

class PagesController < ApplicationController
  def action
    head :ok
  end
end
于 2016-01-09T01:31:31.670 に答える