A better method for Rails validation error management

Hi,

I’ve been looking into several ways of doing user error management and
display but I’m not sure if error_messages_for is the right way. The
problem is that I end up writing a ton of ‘if’ error_messages_for @obj
in my layout template as I’d like to display error messages right below
my header. Problem is that this isn’t that great as it relies on
instance variable names defined in my actions. What if I want to change
them later on? Also, every page that gets rendered will have to check
this block in the layout to make sure none of the instance variablse
have errors in them.

Does anybody know of a much more cleaner and better way? Errors coming
out of validation should get displayed under the header but I don’t want
to have to run through all objects. This just doesn’t seem right for
the non-error cases.

Any help would be appreciated on a better way to do validation based
error display along with internal exception based error management,

Sam.

Sam D. <rails-mailing-list@…> writes:

Any help would be appreciated on a better way to do validation based
error display along with internal exception based error management,

Sam.

Take a look at
http://api.rubyonrails.org/classes/ActiveRecord/Errors.html for
all the things you can do with your @item.errors object

Gareth