Creating an Ajax Timer in Ruby / Rails?

I am trying to find the best solution for creating a game round timer in Ruby / Rails. Right now I'm just recording notes, but theoretically I would like to set a 30 second timer in every round of game activity. As soon as the timer reaches 0, the user queue will end.

At the end of Ruby, I know that I can accomplish this with a while and sleep (30) loop or some combination of the Timer class.

However, I keep trying to develop a better way to show the user the time remaining on the watch. Use Ajax? periodiocally_call_remote? What should I answer?

Just thinking out loud, I thought I would ask the crowd.

+4
source share
2 answers

Create a javascript timer . When the countdown is over, call the end_turn () method.

I would not want to hit the server every second just for the countdown. You can do all this on the client side and only hit the server when the queue is complete (or a step has been taken)

+2
source

I would go with periodiocally_call_remote . I do not know if this would cause problems with Internet Explorer 6 or not.

0
source

Source: https://habr.com/ru/post/1301452/


All Articles