嘿,我想知道rails中render方法的位置选项是什么。这里的文档http://guides.rubyonrails.org/layouts_and_rendering.html表明:
“您可以使用:location选项设置HTTP Location标头:”
但是我不知道你为什么会这样做,或者你会用它做什么。
答案 0 :(得分:16)
实际上,location
选项用于在处理请求时重定向到新资源。例如,
render :xml => post.to_xml, :status => :created, :location => post_url(post)
告诉收件人已创建帖子的XML文件,您将从post_url(post)
获取此文件。因此,GO THERE;)
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
标题的详细信息。
答案 1 :(得分:0)
Location header
用于重定向页面。