Rails 3: Show validation errors for simple_form with ajax
I am using rails3 with simple_form gem and :remote=>true (开发者_如何学JAVAajax).
How to I show validation error with :remote=>true?
Thanks
Use the javascript rails callbacks to do this.
See how do this here: http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/
My approach with this situation (validation errors on ajax submission) has been to pack up the errors off the form and handle them client side. I have been doing all my data using JSON so I send them back as a hash of input => long message. The input id allows me to easily turn on the form input "red" and the long message goes wherever you're putting the generalized messages...
精彩评论