Forum: Ruby on Rails RE: AJAX in Ruby on Rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Charles Squires (Guest)
on 2005-12-12 20:04
(Received via mailing list)
Sorry, I forgot to put that in my example.  In the index.rhtml I was
importing the JavaScript prototype library.
Rich C. (Guest)
on 2005-12-12 21:22
(Received via mailing list)
You might make sure your <form> has onSubmit='...return false'.  It
sounds
like may be your browser's fault--pulling into a new page rather than
inserting into the <div>.  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.
Ugo C. (Guest)
on 2005-12-13 12:15
(Received via mailing list)
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:

<div id="vote-form-34" style="border:2px;background:#ddd">
            <form action="/browse/vote" method="post" onsubmit="new
Ajax.Updater('vote-form-34', '/browse/vote', {asynchronous:true,
evalScripts:true, parameters:Form.serialize(this)}); return false;">

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/
Justin F. (Guest)
on 2005-12-14 06:07
(Received via mailing list)
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
Ugo C. (Guest)
on 2005-12-14 10:19
(Received via mailing list)
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/
Francois P. (Guest)
on 2005-12-14 10:37
(Received via mailing list)
before you do this, be sure to upgrade to 1.0 as the prototype lib is
updated in this release.
Ugo C. (Guest)
on 2005-12-14 12:23
(Received via mailing list)
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/
Justin F. (Guest)
on 2005-12-15 07:07
(Received via mailing list)
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
Ugo C. (Guest)
on 2005-12-15 10:43
(Received via mailing list)
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/
Ugo C. (Guest)
on 2005-12-15 10:46
(Received via mailing list)
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/
Kelly F. (Guest)
on 2006-04-12 06:11
(Received via mailing list)
Did you solve this problem? I'm experiencing the same problem.

Thanks,

-Kelly
This topic is locked and can not be replied to.