2012-02-20 46 views
0

我想使用Ror.But顯示系統在頁面上的當前時間。但時間會像在手錶上一樣變化,在不刷新頁面的情況下,秒數將不斷更改。使用Rails以真實滴答格式在頁面上顯示當前時間

目前我使用此代碼

Time.now.in_time_zone("Central Time (US & Canada)").to_s.split(" ").second 

是顯示時間,它顯示

06:01:43 

但問題是,它顯示靜態的時間,秒不會增加像手錶。

+1

你需要在Javascript上做到這一點。 – shingara 2012-02-20 12:32:18

回答

2

後,我用這個代碼,並享受....

$(document).ready(
     function() { 
      setInterval(function() { 
       $('.main-time-portion').load('/dashboard/give_time'); 
      }, 1000); 
     }); 

其中dashboard是我的控制器和give_time是行動

def give_time 
    @time = Time.now.utc.to_s.split(" ").second 
    render :partial => 'shared/time_portion' 
end