不推荐使用“:nothing”选项,将在Rails 5.1中删除

时间:2016-01-09 01:31:32

标签: ruby-on-rails ruby-on-rails-5

此代码在rails 5

CaesarCipherTwoKeys in class CaesarCipherTwoKeys cannot be applied to given types; required int,int; found int...

导致以下弃用警告

class PagesController < ApplicationController
  def action
    render nothing: true
  end
end

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:146)

根据the rails source,这是在轨道5中传递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

只需将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

alternatively you can use class PagesController < ApplicationController def action render body: nil end end

head :ok