开发者

What does `:location => ...` and `head :ok` mean in the 'respond_to' format statement?

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 |fo开发者_运维知识库rmat|
    format.xml  { render :xml => @user, :status => :created, :location => @user }
end

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


  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)

  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜