2012-03-21 2 views

답변

2

예 흥미로운 상황 나는 부분적으로 표시 시간을 차지하고 jquery ajax 호출로 새로 고침해야한다고 생각합니다. 따라서 매 초마다 새로 고치고 아약스 호출 빈도를 설정할 수 있습니다. 여기에 몇 가지 코드가 도움이 될 수 있습니다.

HTML 코드 : time_portion의 부분의

<div class="time-rect-container"> 
    <%= render :partial => 'shared/time_portion' %> 
</div> 

코드입니다. 그것은 단지 시간을 보여줍니다.

<h1>System Time</h1> 

<div class="time-detail"><p><%[email protected]%></p></div> 

컨트롤러 코드 :

def give_time 

    @time = Time.now.strftime("%H:%M:%S ") 

    render :partial => 'shared/time_portion' 

end 

그리고 JQuery와 아약스 호출에 의해이 부분 새로 고침 나는 1 초를 위해 그것의 주파수를 설정하고 변경할 수 있습니다.

$(document).ready(function() { 
    setInterval(function() { 

     $('.time-rect-container').load('/dashboard/give_time'); 

    }, 1000); 
}); 
+0

이 왜 백엔드을 사용 표시 할 이!? 당신은 단지'new Date();를 사용할 수 있습니다 ... ... ' – rfunduk

+0

컨트롤러 코드는 어디에 있습니까? Application_Controller.rb? 응용 프로그램 controller.rb에서 – Bruno

+0

예. 그러나 필요에 따라 다른 컨트롤러를 보관할 수 있습니다. – Kashiftufail

0

JS Clock

$(document).ready(function(){ 
    $('some-selector').jsclock(); 
}); 
관련 문제