这个代码在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.
我该如何解决?
根据导轨源,这在通过nothing: true
导轨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