Forum: Ruby on Rails Model validation when using ajax & form_remote_tag...

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
James W. (Guest)
on 2006-05-02 22:21
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

def render_error(object = '', status = 500)
    render(:text => (object.errors.full_messages.join(", ") rescue
object.to_s), :status => status)

Throwing a 500 status error stops that annyoing "cannot find template"

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.

This topic is locked and can not be replied to.