Forum: Ruby on Rails How to read ActiveRecord errors

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F869b7c184a4a0ac9b1ecd664d1c0717?d=identicon&s=25 f church (Guest)
on 2006-04-19 08:49
(Received via mailing list)
How can ActiveRecord errors be read within the model itself?

I am deliberately putting error records in the form, however after the
save
command, the error messages show up in the browser.

How can the ActiveRecord messages be retrieved in the code itself,
either in the
model or the controller code, something like a try, except, catch ?
3dd4b52a0946bd698b1d1635a46ea3a3?d=identicon&s=25 François Beausoleil (fbeausoleil)
on 2006-04-19 09:23
(Received via mailing list)
Hi !

2006/4/19, f church <rails@adontendev.net>:
> How can ActiveRecord errors be read within the model itself?
>
> I am deliberately putting error records in the form, however after the save
> command, the error messages show up in the browser.
>
> How can the ActiveRecord messages be retrieved in the code itself, either in the
> model or the controller code, something like a try, except, catch ?

Not sure exactly what you are after.  There's begin/rescue/ensure to
catch exceptions, but this doesn't catch model validation errors.

If you want to access validation errors, look at the #errors method
and the Errors class on the Rails API:  http://api.rubyonrails.com/

Hope that helps !
This topic is locked and can not be replied to.