【发布时间】:2018-07-06 11:58:12
【问题描述】:
这似乎是基本的,但我是 Ruby/Rails 初学者。我只需要在控制器中返回 HTTP 204。 会
respond_to do |format|
format.html
end
返回 204?
【问题讨论】:
标签: ruby-on-rails ruby
这似乎是基本的,但我是 Ruby/Rails 初学者。我只需要在控制器中返回 HTTP 204。 会
respond_to do |format|
format.html
end
返回 204?
【问题讨论】:
标签: ruby-on-rails ruby
head :no_content
使用 Rails 3.2.x、4.x 测试。它会导致控制器方法以 204 No Content HTTP 状态代码进行响应。
在名为 foobar 的控制器方法中使用它的示例:
def foobar
head :no_content
end
【讨论】:
看head方法:
返回没有内容的响应(仅是标题)。选项 参数被解释为标题名称和值的哈希。
【讨论】:
如果你根本不想渲染任何东西,你可以这样做:
render :nothing => true, :status => 204
或者像这样:
render :nothing => true, :status => 204 and return
或者您可以将:status => 204 部分与任何其他渲染命令一起使用
【讨论】:
head 而不是render :nothing 应该更明确,正如Ruby On Rails Guide 所解释的那样