Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help w/ errors.add_to_base between controller and model

Status
Not open for further replies.

clemcrock

Programmer
Dec 17, 2006
63
US
Help w/ errors.add_to_base between controller and model

Hello,

I'm having trouble in routing some errors between model and
controller. The errors produced in the controller
(invite_controller.rb) are collected and spit out nicely in a
flash[:validate] method as such:

Code:
if errors.size > 0
   flash[:validation] = errors.join('<br />')
end


Errors produced in the model (invite.rb) are displayed w/in a giant page
failure explosion and are not routed into the flash[:validate] method.

The code for the the method is as follows:

Code:
self.errors.add_to_base("an invitation has already been sent to
#{email}")

Is there a way where I can route the model errors to the
flash[:validate] method as I am in the controller?

Thanks for your help!

 
The errors for your model objects will be available via the objects that they were added too.

So, in your controller code, if you have a model object called "invitation", and you try to save it but get validation errors, then you can retrieve the errors by doing something like
Code:
invitation.errors.full_messages.join(", ")

See ActiveRecord::Errors for more.

Does that help?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top