validation triggered when click back button Rails
A user submits a form and all of the information is valid.
I just discoverd that when they click the back button the following validation gets trigger开发者_运维知识库ed.
validates_format_of :email,
:with => /^[A-Z0-9._%-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i,
:message => "should be something like youremail@something.com"
Why is this happening and how can I stop it from being triggered?
If the users re-submit the form - which the browser warns them about and which always happens when you go BACK to a POST-request in a browser - there is nothing you can do. It's how browsers work. Besides, just for clarity of language, it's not the "going back" that triggers a validation. It's the operation on the model you specified the validation for, probably before_save. So there is a model.save operation going on, and that's likely triggered (don't know YOUR code, you could write @somemodel.save
anywhere in your controller, but it's standard) by that repeated POST operation. Which comes from the user, in the end. one should not go "back" to a form that was posted, it's the same all over the Internet regardless of backend technology.
精彩评论