问题
Hey I am wondering what the location option for the render method in rails is. The docs here http://guides.rubyonrails.org/layouts_and_rendering.html states:
"You can use the :location option to set the HTTP Location header:"
But I have no idea why you would do this, or what you would use this for.
回答1:
Actually location
option is used to redirect to a new resource as part of processing the request. For example,
render :xml => post.to_xml, :status => :created, :location => post_url(post)
is telling the recipient that a XML file for the post is created and you will get this from post_url(post)
. Hence GO THERE ;)
render
method does this by setting the Location
option in response object
... ... ...
if location = options[:location]
response.headers["Location"] = url_for(location)
end
... ... ...
You can find details about Location
header here http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30.
回答2:
The Location header
is for redirecting the page.
来源:https://stackoverflow.com/questions/12084431/rails-what-is-the-location-option-for-in-the-render-method