方法
- H
实例公共方法
head(status, options = nil) 链接
返回一个没有内容(只有头信息)的响应。options 参数被解释为一个包含头信息名称和值的哈希表。这允许您轻松地返回一个只包含重要头信息的响应。
head :created, location: person_path(@person)
head :created, location: @person
它也可以用来返回异常情况。
return head(:method_not_allowed) unless request.post?
return head(:bad_request) unless valid_request?
render
请参阅 Rack::Utils::SYMBOL_TO_STATUS_CODE
以获取所有有效的 status
符号列表。
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_controller/metal/head.rb, line 21 def head(status, options = nil) if status.is_a?(Hash) raise ArgumentError, "#{status.inspect} is not a valid value for `status`." end status ||= :ok if options location = options.delete(:location) content_type = options.delete(:content_type) options.each do |key, value| headers[key.to_s.split(/[-_]/).each { |v| v[0] = v[0].upcase }.join("-")] = value.to_s end end self.status = status self.location = url_for(location) if location if include_content?(response_code) unless self.media_type self.content_type = content_type || ((f = formats) && Mime[f.first]) || Mime[:html] end response.charset = false end self.response_body = "" true end