Rails:render方法中的位置选项是什么
嘿,我想知道rails中render方法的位置选项是什么。 这里的文档http://guides.rubyonrails.org/layouts_and_rendering.html说明:
“您可以使用:location选项设置HTTP Location标头:”
但我不知道你为什么会这样做,或者你会用它做什么。
实际上, location
选项用于在处理请求时重定向到新资源。 例如,
render :xml => post.to_xml, :status => :created, :location => post_url(post)
告诉收件人已创建post的XML文件,您将从post_url(post)
获取此post_url(post)
。 因此GO GOERE;)
render
方法通过在响应对象中设置Location
选项来完成此操作
... ... ... if location = options[:location] response.headers["Location"] = url_for(location) end ... ... ...
您可以在http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30找到有关Location
标题的详细信息。
Location header
用于重定向页面。