Ajax Updater mystery

I have a form which contains the following updater:

<input name='commit'        type='submit'        value='Enter'        onClick="new Ajax.Updater('div_recipients',                                  'updtrecipients',    {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)}                                           ); return false;">

When I use this form in a 'new' action, it works as expected. However, When I try it with an 'edit/<id> action, it fails to call updtrecipients, and instead calls edit, which renders the whole page into div_recipients. I have noticed in the logs that params contains :id=>'updtrecipients' when this happens. Anyone know what's going on? For now I have just added         if request.xhr?             updtrecipients and return true         end to the top of my edit action, which works, but if anyone has a solution that is less ugly, I'd like to know what it is.

Thanks much

Ken

Hello Kenneth,

       onClick="new Ajax.Updater('div_recipients',                                  'updtrecipients',    {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)}                                           ); return false;">

Your problem is the URL of the Updater. You're telling it to POST relative to the current URL.

If you have /contacts/new, you'll get /contacts/updtrecipients, and if you have /contacts/edit/13, you'll get /contacts/edit/updtrecipients.

You're much better off using absolute URLs, or using named routes (which give you absolute URLs always).

Hope that helps !

Quoth Fran??ois Beausoleil (francois.beausoleil@gmail.com):

Hello Kenneth,

> onClick="new Ajax.Updater('div_recipients', > 'updtrecipients', > {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)} > ); return false;">

Your problem is the URL of the Updater. You're telling it to POST relative to the current URL.

If you have /contacts/new, you'll get /contacts/updtrecipients, and if you have /contacts/edit/13, you'll get /contacts/edit/updtrecipients.

You're much better off using absolute URLs, or using named routes (which give you absolute URLs always).

Hope that helps !

That seems to have done the trick. Thanks.

Ken