I would like to have Ajax form in Rails so i'm using form_remote_tag. The field i would like to submit is email address - how can i use the Rails validations together with form_remote_tag?
+1
A:
In your form processing controller action decide whether
- you load flash[:notice] with
validation errors and lead the user
back to the form view
OR - let her go ahead and process the valid data, (leading to the next step)
You can (should) make this decision based on validations
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
Fer
2009-05-11 12:55:53
+3
A:
We're using form_remote_tag with the :update option and paste the whole form into a partial. Once the form is submitted and validation fails, the partial is being rendered again and all error messages will show up.
This is the workflow:
- Call "edit" action
- Display form from a partial, use form_remote_tag with :update option
- Submit form to "update" action
- Validate data
- Validation failed? Display partial again with error messages
- Validation passed? Display form with some success message
Matt
2009-05-11 18:26:47