How to read ActiveRecord errors

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 ?

Hi !

2006/4/19, f church [email protected]:

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 !