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.
我该如何解决这个问题?
发布于 2016-01-09 09:31:32
根据the rails source的说法,这是在rails 5中传递nothing: true
时在引擎盖下完成的。
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
因此,只需用body: nil
替换nothing: true
就可以解决这个问题。
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
https://stackoverflow.com/questions/34688726
复制相似问题