James Whittaker
2006-May-02 18:21 UTC
[Rails] Model validation when using ajax & form_remote_tag...
I am trying to understand why model validation error reporting in Rails is so complicated compared to non ajax model validation. In my normal form I use <%= error_messages_for ''user'' %> in my view and I get a nice error message displayed when the user inputs invalid information into the form. When I convert that form to use Ajax using form_remote_tag the error_messages_for no longer works ,because the page does not get reloaded. I have searched everywhere for a simple elegant solution inline with DHH " beautiful code" line. In the code for Typo they partly solve the issue by calling this method when a begin & rescue trap is called: def render_error(object = '''', status = 500) render(:text => (object.errors.full_messages.join(", ") rescue object.to_s), :status => status) end Throwing a 500 status error stops that annyoing "cannot find template" message. This just renders text to the browser. Not very nice really. I want the SAME form as the error_messages_for gives. There should be a better solutions to this to give comminality to error messages across an application. I have tried using a helper method passing into it the object but that does not seem to work. Help! -- Posted via http://www.ruby-forum.com/.