Digital Clock

Hello Group. I got my first page up and running and now I'm trying to make it look a bit nicer. I was thinking about putting a clock on the page, can anyone point me to a tutorial or have a routine already done? I'm currently using the Time.now(:short) form, but that is just static. Anyway any help would be greatly appreciated Thanks James

No Ruby required. Just use JavaScript.. http://www.javascript-page.com/clock.html

Preston

try AJAX periodically_call_remote

example

# demo4.rhtml <h1>Test periodically_call_remote</h1> <div id='show_date_time_id' style="background-color: #eee"></div> <%= periodically_call_remote(:update => 'show_date_time_id',:url => { :action => :show_date_time }, :frequency => 1 )%>

# ajax_controller.rb   def show_date_time      render :text=>"Now : #{DateTime.now.to_s}"   end

try AJAX periodically_call_remote

example

# demo4.rhtml <h1>Test periodically_call_remote</h1> <div id='show_date_time_id' style="background-color: #eee"></div> <%= periodically_call_remote(:update => 'show_date_time_id',:url => { :action => :show_date_time }, :frequency => 1 )%>

# ajax_controller.rb   def show_date_time      render :text=>"Now : #{DateTime.now.to_s}"   end

That would be a very unwise decision, for quite a number of reasons:

  1. Your server will be bombarded with requests

  2. The clock will never show the right time, because of latency between the request and the response.

So, if you want to show the right time, use client-side javascript, period.

I thought the same thing, just imagine one lets the browsertab open for hours without any further action.

Anyway, I need to show my users the servertime, there might be a difference to the users machinetime, even if we are talking about a few minutes, so the best would be to make an initial call to rubys TimeClass for getting the servertime and from then on to display/update the time clientside.

Even if it´s offtopic, if someone has an approach it would be very welcome

matthi

Although it wouldn’t exactly be 100% accurate, it would only differ a few seconds from the actual server time. Calculate the offset from the server time with the client’s time using one request, then display the client side time plus or minus the offset.

Best regards

Peter De Berdt