我正在使用Ruby on Rails 3,我想知道:location => ...
和head :ok
语句在以下代码中的含义,它们如何工作以及我应该如何使用它们。
respond_to do |format|
format.xml { render :xml => @user, :status => :created, :location => @user }
end
respond_to do |format|
format.xml { head :ok }
end
答案 0 :(得分:69)
render ... :location => @user
会设置HTTP location header以通知客户端新创建的资源的位置(即其网址)
head :ok
sets render
to return an empty response (so just the header, no body) with status 200. head :ok
是render nothing: true, status: :ok
的简写
Here's a list of all the :status
options you can use for setting the appropriate status code.