2012-02-09 61 views

回答

4

因为HTML是的一部分Rails应用程序,你可以使用默认标准的HTML重定向选项:

<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html"> 

变化0以秒数要は它在重定向之前。

在另一方面,你可以使用JavaScript(也Rails应用部分):

<html> 
<head> 
<script type="text/javascript"> 
function delayedRedirect(){ 
    window.location = "/default.aspx" 
} 
</script> 
</head> 
<body onLoad="setTimeout('delayedRedirect()', 3000)"> 
<h2>You'll be redirected soon!</h2> 
</body> 
</html> 
+0

但我想重定向user_path,我怎么能不使用rails? – 2012-02-09 07:53:30

+1

@roine,只需用'“<%= user_path%>”'替换'“/default.aspx”'。 – Mischa 2012-02-09 07:56:43

+0

@Mischa它适用于你用'“<%= user_path%>”替换'“/default.aspx”'因为对我来说它不起作用。我不认为JavaScript可以识别轨道标签 – 2012-02-09 08:26:37

0

您可以使用sleep方法

sleep(2.0) 
    redirect_to root_path 
+0

的问题是,该页面无法显示。我想显示一个页面,并在这个页面上等待2秒钟,但它不起作用 – 2012-02-09 07:33:38

+2

这将消耗两个宝贵的秒钟到网络工作者和所有后续的请求到服务器。我强烈建议不要这样做。 – bswinnerton 2014-10-25 22:54:57