The “:nothing” option is deprecated and will be removed in Rails 5.1

后端 未结 1 782
孤独总比滥情好
孤独总比滥情好 2020-12-13 16:57

This code in rails 5

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

results in the follow

相关标签:
1条回答
  • 2020-12-13 17:19

    According to the rails source, this is done under the hood when passing nothing: true in rails 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
    

    Just replacing nothing: true with body: nil should therefore solve the problem.

    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
    
    0 讨论(0)
提交回复
热议问题