Lin*_*der 101 ruby-on-rails ruby-on-rails-5
这个代码在rails 5中
class PagesController < ApplicationController
def action
render nothing: true
end
end
Run Code Online (Sandbox Code Playgroud)
导致以下弃用警告
DEPRECATION WARNING: :nothing` option is deprecated and will be removed in Rails 5.1. Use `head` method to respond with empty response body.
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
Lin*_*der 158
根据导轨源,这在通过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
Run Code Online (Sandbox Code Playgroud)
只需更换nothing: true与body: nil因此应该解决的问题.
class PagesController < ApplicationController
def action
render body: nil
end
end
Run Code Online (Sandbox Code Playgroud)
或者你可以使用 head :ok
class PagesController < ApplicationController
def action
head :ok
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21999 次 |
| 最近记录: |