2012-02-09 63 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