首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >不建议使用":nothing“选项,该选项将在Rails 5.1中删除

不建议使用":nothing“选项,该选项将在Rails 5.1中删除
EN

Stack Overflow用户
提问于 2016-01-09 09:31:32
回答 1查看 28.5K关注 0票数 119

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.

我该如何解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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
票数 189
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34688726

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档