RE: AJAX in Ruby on Rails

Sorry, I forgot to put that in my example. In the index.rhtml I was
importing the JavaScript prototype library.

You might make sure your has onSubmit=’…return false’. It
sounds
like may be your browser’s fault–pulling into a new page rather than
inserting into the

. This will happen if the “submit” is not
prevented
by “return=false”.

Rich C.
removed_email_address@domain.invalid
www.RoboSUV.com AKA www.GrandChallenge.info

----- Original Message -----
From: “Charles Squires” removed_email_address@domain.invalid
To: removed_email_address@domain.invalid
Sent: Monday, December 12, 2005 10:03 AM
Subject: RE: [Rails] AJAX in Ruby on Rails

Sorry, I forgot to put that in my example. In the index.rhtml I was
importing
the JavaScript prototype library.

FWIW, I’m having the same problem. I also made sure to include the
necessary javascripts (:default, which expands to prototype.js and
scriptaculous.js). The generated form tag is the following:

and the “return false” statement is there. Still, the request goes
through as if it was a regular HTTP request and not an Ajax request.

I am using the latest Locomotive download, which includes Rails 0.14.1
IIRC.

Ugo


Ugo C.
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/

Ugo C. wrote:

I am using the latest Locomotive download, which includes Rails 0.14.1 IIRC.

In case you didn’t know, you can open Terminal from Locomotive and
update its gems as normal, i.e.

sudo gem update rails --include-dependencies

regards

Justin

Il giorno 14/dic/05, alle ore 05:06, Justin F. ha scritto:

Ugo C. wrote:

I am using the latest Locomotive download, which includes Rails
0.14.1 IIRC.

In case you didn’t know, you can open Terminal from Locomotive and
update its gems as normal, i.e.

sudo gem update rails --include-dependencies

Thank you. I am running 0.14.3 now, but still I have the same
problem. However, this looks very much like a client-side problem.
The initial page served by Rails looks fine and the response to the
subsequent submit looks fine too, it’s just that the browser (Firefox
1.5, OS X Tiger. Safari, by the way, does nothing at all) sends the
POST via HTTP and not via XMLHttpRequest. The Javascript libraries
are there and Firefox Javascript console shows absolutely no warnings
or errors. So, I don’t think even upgrading Rails to 1.0 could change
much in this respect.

I’m starting to think I need to install Venkman and start tracing
through the Prototype code :(.

Ugo


Ugo C.
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/

OK, I found what the problem was: my form consisted only of a group
of radio buttons, with no submit button, so I had added a
onchange=“form.submit()” attribute to every radio button in order to
trigger a submit as soon as the button was clicked. Apparently,
calling form.submit() completely bypasses the onsubmit handler set
for the form, and the Prototype AJAX code was never called!

Now I got it to work by removing the onchange handler from buttons
and adding a submit button, but this in not exactly what I want. So,
my question is: is there a simple way to invoke the onsubmit form
handler from the onchange handler of a form control?

Ugo


Ugo C.
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/

before you do this, be sure to upgrade to 1.0 as the prototype lib is
updated in this release.

Ugo C. wrote:

update its gems as normal, i.e.
Firefox Javascript console shows absolutely no warnings or errors. So,
I don’t think even upgrading Rails to 1.0 could change much in this
respect.

I didn’t think it would solve your problem - I just mentioned it in case
you thought you would have to wait for a new version of Locomotive in
order to get a more up to date version of Rails.

I’m starting to think I need to install Venkman and start tracing
through the Prototype code :(.

Do you have the Pragmatic Ajax beta book? The latest version has a new
chapter on debugging Ajax applications.

BUT I have just tried this application, using the downloadable code for
the AWDR book, and it works for me, both in Safari and Firefox 1.5.

I copied the web2 project into my rails projects directory, and opened
it in Locomotive (newly upgraded to Rails 1.0), then used

rails .

in the project directory to bring scripts, javascripts, config etc. up
to date (I updated everything except database.yml, but it turns out that
it wouldn’t have mattered if I had updated that too, as the demos don’t
use a database).

Then I tried the list demo and the guesswhat demo, and both work
(although I’m not seeing the yellow fade in the list demo).

regards

Justin

Il giorno 15/dic/05, alle ore 06:05, Justin F. ha scritto:

BUT I have just tried this application, using the downloadable code
for the AWDR book, and it works for me, both in Safari and Firefox
1.5.

I found what the problem is, and have sent the explanation to this
list, but it looks like my message didn’t make it through, so I’ll
try to send it again.

Ugo


Ugo C.
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/

Did you solve this problem? I’m experiencing the same problem.

Thanks,

-Kelly

OK, I found what the problem was: my form consisted only of a group
of radio buttons, with no submit button, so I had added a
onchange=“form.submit()” attribute to every radio button in order to
trigger a submit as soon as the button was clicked. Apparently,
calling form.submit() completely bypasses the onsubmit handler set
for the form, and the Prototype AJAX code was never called!

Now I got it to work by removing the onchange handler from buttons
and adding a submit button, but this in not exactly what I want. So,
my question is: is there a simple way to invoke the onsubmit form
handler from the onchange handler of a form control?

Ugo


Ugo C.
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/