Ajax and Rails with two people?

Hi there,

I’m looking for a little guidance for a project I’d like to start. I’m
fairly familiar with Rails, but still new to Ajax. I want a part of an
app to include a back-and-forth between two people, kind of like a
turn-based strategy game. Is Ajax able to do something like that? Can it
observe when one person has passed it over to the other, and activate
the second person’s screen accordingly?

Thanks!

Dave

On 7/7/07, Dave A. [email protected] wrote:

Hi there,

I’m looking for a little guidance for a project I’d like to start. I’m
fairly familiar with Rails, but still new to Ajax. I want a part of an
app to include a back-and-forth between two people, kind of like a
turn-based strategy game. Is Ajax able to do something like that? Can it
observe when one person has passed it over to the other, and activate
the second person’s screen accordingly?

You need something on the server side to tie the two people together.
Javascript can only communicate with the server it’s being served
from. You can send ajax requests every few seconds to the server to
pick up new events that have happened. Can lead to a very busy server
though:)

Also, if you have a lot of ajax calls I suggest just using prototype
directly and not use the rails helpers. It can improve performance
quite a bit.

Chris

Dave A. wrote:

I’m looking for a little guidance for a project I’d like to start. I’m
fairly familiar with Rails, but still new to Ajax. I want a part of an
app to include a back-and-forth between two people, kind of like a
turn-based strategy game. Is Ajax able to do something like that? Can it
observe when one person has passed it over to the other, and activate
the second person’s screen accordingly?

Google for my street name, “how to chat”, Rails, and Ajax.

The best raw Ajax can do is a periodically_call_remote with a timer set
to
above a second. If you try to go faster than that, the internets’ pipes
will
start thrashing.

If you need split-second resolution, then you need a system that leaves
an
internet connection open. That would be Juggernaut; it uses a small
Flash
dot on your screen to call-back to the server and leave this connection
open. You can get sub-second resolution like this, and both browsers
generally see the update at the exact same time.


Phlip
Test Driven Ajax (on Rails) [Book]
“Test Driven Ajax (on Rails)”
assert_xpath, assert_javascript, & assert_ajax

Google for my street name, “how to chat”, Rails, and Ajax.

The best raw Ajax can do is a periodically_call_remote with a timer set
to
above a second. If you try to go faster than that, the internets’ pipes
will
start thrashing.

If you need split-second resolution, then you need a system that leaves
an
internet connection open. That would be Juggernaut; it uses a small
Flash
dot on your screen to call-back to the server and leave this connection
open. You can get sub-second resolution like this, and both browsers
generally see the update at the exact same time.

Thanks for your answers. I don’t think I’ll need an instantaneous
system, a second or two lag is just fine. I am concerned about the
server load, though. I’ll look into Juggernaut – seems promising and
I’m not adverse to a spec of flash.

Thanks again!