I have a form I am submitting via AJAX (using prototype and the built-in rails 'form_remote_tag' helper).
What I would like is to update one div (a status area) if there are form validation errors but a different div (the div where the form lives) if the submit goes through sucessfully.
My code looks something like this:
<div id="recipe-status"><!-- I want form validation errors to go here --></div>
<div id="recipe">
<%= form_remote_tag(:update => "recipe-status",
:before => "Element.show('wait-indicator')",
:success => "Element.hide('wait-indicator')",
:complete => visual_effect(:appear, "recipe-status"),
:url => { :action => 'import', :id => @recipe.id },
:failure => "alert('Unable to import recipes at present')") %>
<-- Form goes here, I want this to be replaced if the submit succeeds -->
</div>
The only way I can think of doing this is to return a HTTP error status if there is a validation error but that seems like a bit of a hack. Is there a cleaner way of doing it at all?