Forum: Ruby on Rails how to show model validation error in a custom view

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.
Ffb15a8418eb7f49060b6764aba1dc52?d=identicon&s=25 Rm Rm (rmehta)
on 2007-02-13 07:41

Based on the validation done in a model, how can I show errors in a
custom manner , eg. instead of showing like :

2 errors prohibited this textbrand from being saved

There were problems with the following fields:

    * Textbrand already exists
    * Textbrand approved is not numeric.

By using in view :

<%= error_messages_for 'textbrand' %>

How can I show messages like :

There were problems with the following fields:

    * Textbrand

    * Textbrand approved

And in the form next to the textbrand , I want to show 'already exists'.
and next to approve text field, I want to show ' is not numeric'.

Any help is greatly appreciated.
9d1310212bb9dfe69ee6b259c7945392?d=identicon&s=25 Sheldon Hearn (sheldonh)
on 2007-02-13 09:50
(Received via mailing list)
You can't achieve what you want with error_messages_for.

You'll have to build up your own error display using error_messages_on
(note on instead of for).

You'd think this would be a perfect opportunity to use a custom form
builder, but take care:

I asked that question over a month ago and still haven't had a reply,
so you may find yourself on your own if you try the custom form
builder approach.

Neither AWDWR nor Rails Recipes deal with this.

This topic is locked and can not be replied to.