问题描述
我正在使用Ruby on Rails 3,我想知道:location => ...
和 head:ok
语句在下面的代码中有意义,它们是如何工作的以及如何使用这些语句。
respond_to do | format |
format.xml {render:xml => @user,:status => :created,:location => @user}
结束
respond_to do | format |
format.xml {head:ok}
end
-
render ...:location => @user
会设置来通知客户新创建的资源的位置(即其URL) -
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 can\should 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
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 :ok
setsrender
to return an empty response (so just the header, no body) with status 200.head :ok
is shorthand forrender nothing: true, status: :ok
.
Here's a list of all the:status
options you can use for setting the appropriate status code.
这篇关于什么`:location => ...`和`head:ok`意思是在'respond_to'格式声明中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!