2012-08-23 20 views

回答

12

其实location选项用于重定向到一个新的资源作为处理请求的一部分。例如,

render :xml => post.to_xml, :status => :created, :location => post_url(post) 

告诉,对于后一个XML文件中创建收件人,你会得到这样的post_url(post)。因此,GO THERE)

render方法,通过

... ... ... 
if location = options[:location] 
    response.headers["Location"] = url_for(location) 
end 
... ... ... 

设置Location选项响应对象,你可以在这里进一步了解http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30Location头细节做到这一点。

+0

哦,好的。例如,如果客户端对服务器做了ajax调用,然后在响应中,位置被定义为某个url,那么ajax应该(根据响应)转到该位置指定的url。否则,如果没有位置,则完成 – hajpoj

+0

是的......确切地说!! 虽然我没有尝试使用Ajax调用,但应该像那样工作! – Samiron

+0

得到它谢谢! – hajpoj

0

Location header用于重定向页面。