Re: AJAX and Model Validations

Maximilian Schöfmann
Mon, 15 Aug 2005 19:23:05 -0000

Hi,

>What would be the best way to handle the errors returned from the
>model''s validation, preferably allowing me to display something
like
>the "errors for @item" helper could for a non-AJAX form?
>
>I know about the :failure option for the form_remote/link_to_remote,
>but do not really know how this relates to specific errors such as
>validations, and how I would trigger the failure on the serverside.
>
>
Some people like to return "custom" HTTP status codes and match them
to
error messages.
I had the same problem and messing around with HTTP status codes just
felt wrong to me.
As the X in Ajax stands for XML, it seemed a good idea to generate some
XML for this task.
In my case I wanted to update a select list and wanted a "cleaned"
version of the entered data in the list (trimmed, special chars removed
etc. anything that''s done before saving to the DB). So the benefit
wasn''t just the server-side validation.
The encoding method of XML-RPC seemed convenient. It''s quite easy to do
with Builder templates and the JavaScript DOM functions.
Here''s a small howto:
http://people.freenet.de/schoefmax/howto/ajax_responses_with_xmlrpc/

HTH,
Max