gpt4 book ai didi

ruby-on-rails - ":nothing"选项已弃用,并将在 Rails 5.1 中删除

转载 作者:行者123 更新时间:2023-12-03 04:48:38 25 4
gpt4 key购买 nike

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.

如何解决这个问题?

最佳答案

根据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

只需将 nothing: true 替换为 body: nil 就可以解决问题。

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

alternatively you can use 头:好的

class PagesController < ApplicationController
def action
head :ok
end
end

关于ruby-on-rails - ":nothing"选项已弃用,并将在 Rails 5.1 中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34688726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com