Reputation: 10885
I want to display current time of system on page using Ror.But time will change like on watch that seconds will be continuously changed without refresh page.
currently i am display time using this code
Time.now.in_time_zone("Central Time (US & Canada)").to_s.split(" ").second
and it display
06:01:43
But the problem is it show static time and seconds not increase like on watch.
Upvotes: 0
Views: 2527
Reputation: 10885
After that I use this code and enjoy....
$(document).ready(
function() {
setInterval(function() {
$('.main-time-portion').load('/dashboard/give_time');
}, 1000);
});
where dashboard
is my controller and give_time
is action
def give_time
@time = Time.now.utc.to_s.split(" ").second
render :partial => 'shared/time_portion'
end
Upvotes: 2