开发者

How could I automatically update and display a variable in a view, in Ruby on Rails?

I have a number of users.

Each user has a number of bets开发者_JAVA技巧, made by and against him.

The total number of bets "belonging" to a user is: bets_won + bets_lost + bets_in_progress.

On each user's profile, the user can set whether or not he had won or lost a bet by clicking a radio button for each bet (won, lost or in progress).

Now, I'd like to display the user's "Winning Percentage" (bets_won / (bets_won + bets_lost) * 100%) on the profile page in real-time; that is, when the user sets a bet to "won" status, his "Winning Percentage" should automatically be updated on his profile without having to refresh the page.

How could this be done?


  1. AJAX polling

  2. WEB Sockets (look at SocketIO)

  3. Or complete COMET like juggernaut (or old version)

For small feature I preffer to use AJAX polling. For big complicated things I use juggernaut. I've never used SocketIO but it looks very sexy

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜