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.
これを修正するにはどうすればいいでしょうか?
ベストアンサー1
によるとレールソースnothing: true
これは、 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
nothing: true
したがって、を に置き換えるだけでbody: nil
問題は解決するはずです。
class PagesController < ApplicationController
def action
render body: nil
end
end
代わりに、 head :ok
class PagesController < ApplicationController
def action
head :ok
end
end