I''m newbie to ruby on rails. In my application, i was trying to show the remaining time the user is allowed to edit an instance record( like milestones, cheklists etc.). I was locking it from multiple users to edit it at the sametime. When the user clicks the edit link_to i need to display the timer in the edit.rhtml I have the javascript function for timer updation. when called it updates the text_field with the time. function update_timer() { var page_loaded_ms = new Date().getTime(); var timeout_ms = 100*1000; var time_left = Math.round((timeout_ms - new Date().getTime() + page_loaded_ms) / 1000); var minutes = Math.floor(time_left/60); var seconds = time_left - (minutes*60); $(''time_left_value'').value = ''Time left: ''+ minutes + '' min'' + zeroPad(seconds, 2)+ '' sec''; setTimeout("update_timer()", 1000); } function zeroPad(number, width) { var s = number.toString(); while (s.length < width) s = "0" + s; return s; } could anyone suggest me a solution for this. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Walker
2010-Jun-04 18:03 UTC
Re: How to show a Timer for lock expiry when editing a recor
Vijay wrote:> I''m newbie to ruby on rails. > In my application, i was trying to show the remaining time the user is > allowed to edit an instance record( like milestones, cheklists etc.). > I was locking it from multiple users to edit it at the sametime. > When the user clicks the edit link_to i need to display the timer in > the edit.rhtmlI thought for a second about attempting to answer this, but quickly realized. DO NOT DO THIS! Pessimistic locking on databases is very, very bad form. Do not attempt to prevent concurrent editing. You''re just asking for trouble. Users of modern applications will not accept pessimistic style record locking. Instead, develop a recovery solution based on an optimistic locking scheme. ActiveRecord has some built-in support for optimistic locking, which will get you started. If the optimistic locking mechanism detects concurrent edits then present that to the user with enough information to recover. P.S. Using *.rhtml extensions is so one-dot-ex. If you''re using a version of Rails 2.0 or higher, switch your views to use *.html.erb. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.