I have non-model custom validation for a data input to a certain
remote_form_tag view. I'd like to have differential responses in the
controller in the following cases:
1) when remote_form_tag post results fail validation, the form view is
updated from the controller, as by the following:
render :update do |page|
page.replace_html 'errors', :partial => "iod_errors"
end
2) when the remote_form_tag post results passes validation, the
controller redirects to another action or view, as in the following:
redirect_to passed_validation_url
Unfortunately, using the following simple parameterization of
form_remote_tag,
<% form_remote_tag :url=>create_iod_url do %>
...
I am succesful in my case 1), but nothing happens at all in my case
2).
I don't understand why the form is expecting anything after it has
submitted to the controller, i.e., I don't understand that a
remote_form_tag handles redirect_to calls. Maybe I don't get where RJS
is 'taking place'.
For the record the solution snippet sequence is as follows:
[controller action: case 1]
render :update do |page|
page.replace_html 'errors', :partial => "iod_errors"
end
[controller action: case 2]
render :update do |page|
page.redirect_to passed_validation_url
end
I don't understand why the form is expecting anything after it has
submitted to the controller, i.e., I don't understand that a
remote_form_tag handles redirect_to calls. Maybe I don't get where RJS
is 'taking place'.
What rjs means is that a response consisting entirely of javascript is
generated. Ajax requests in prototype come in two flavours: Either
they expect to get a fragment of html back which they insert into a
specific place in the DOM or they expect to get some javascript back
in which case they execute it. Stuff like link_to_remote and
remote_form_for will create the former (Ajax.Updater) if you supply
Ajax.Request if not