[ruby-on-rails] “: nothing”옵션은 더 이상 사용되지 않으며 Rails 5.1에서 제거됩니다.

레일 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.

이 문제를 어떻게 해결합니까?



답변

레일 소스 에 따르면 이것은 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

그냥 교체 nothing: true와 함께하기 body: nil때문에 문제를 해결해야한다.

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

또는 사용할 수 있습니다 head :ok

class PagesController < ApplicationController
  def action
    head :ok
  end
end


답변