`:location => 是什么意思?...` 和 `head :ok` 在“respond_to"格式语句中是什么意思? [英] What does `:location => ...` and `head :ok` mean in the 'respond_to' format statement?

查看:5

问题描述

我正在使用 Ruby on Rails 3,我想知道 :location =>;...head :ok 语句表示以下代码,它们如何工作以及我应该如何使用它们.

I am using Ruby on Rails 3 and I would like to know what the :location => ... and head :ok statements mean in following code, how they work and how I canshould use those.

respond_to do |format|
    format.xml  { render :xml => @user, :status => :created, :location => @user }
end

respond_to do |format|
    format.xml  { head :ok }
end

推荐答案

  1. 渲染... :location =>@user 将设置 HTTP 位置标头 通知客户端新创建的资源(即它的 URL)

  1. render ... :location => @user will set the HTTP location header to inform the client of the location of the newly created resource (that is, its URL)

head :okrender 设置为返回一个空响应(所以只有标题,没有正文),状态为 200. head :ok 是 <代码>不渲染:true,状态::ok.
这里列出了您可以使用的所有 :status 选项用于设置适当的状态码.

head :ok sets render to return an empty response (so just the header, no body) with status 200. head :ok is shorthand for render nothing: true, status: :ok.
Here's a list of all the :status options you can use for setting the appropriate status code.

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆