Kashiftufail
Kashiftufail

Reputation: 10885

Show current time on page in real ticks format using Rails

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

Answers (2)

Kashiftufail
Kashiftufail

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

zachar
zachar

Reputation: 1095

Just use jQuery plugin. There are plenty of them (styled already):

http://www.webdeveloperjuice.com/2010/02/07/7-wonderful-analog-and-digital-clocks-using-css-and-javascript/

Upvotes: 0

Related Questions