How do I use form_remote_tag along with validations?
2 answers
We use form_remote_tag with the: update option and insert the entire form into a partial. After the form is submitted and validated, no partial processing is performed and all error messages will be displayed.
This is the workflow:
- Call action "change"
- Display form from partial, use form_remote_tag with: update option
- Submit the form to "update".
- Confirm data
- Failed to complete validation? Display the partial number again with the error message
- Checkout passed? Display form with some success message
+3
a source to share
In your form controller processing routine, decide
- you load flash [: notice] with a validation error and bring the user back to the view form
OR - let it go ahead and process the valid data, (leading to the next step)
You can (should) make this decision based on validation
def create
m = Model.new(params)
if m.valid?
m.save
#load flash with succes message
else
#load flash with error messages from m.errors
#render the form again
end
end
+1
a source to share