Creating an Ajax timer in Ruby/Rails?
I'm trying to figure out the best solution to create a "game-round" timer in Ruby/Rails. Right now I'm just jotting notes, but in theory I'd like to set a 30 second timer on each round of game activity. Once the timer hits 0, the users turn is over.
On Ruby's end, I know I can accompli开发者_StackOverflow中文版sh this with a while loop and sleep(30), or some combination of the Timer class.
However, i'm getting stumped trying to design the best way to show the user their time left on the clock. Use Ajax? periodiocally_call_remote? What should I query for?
Just thinking out loud, figured I'd ask the crowd.
Build a javascript timer. When the countdown is over, call your end_turn() method.
I wouldn't want to hit the server every second just for a countdown. You can do it all client-side and only hit the server when the turn is over (or a move is made)
I would go with periodiocally_call_remote
. I don't know if this will cause issues with Internet Explorer 6 or not.
精彩评论