# Help w/ errors.add\_to\_base between controller and model

**URL:** <https://www.ruby-forum.com/t/help-w-errors-add-to-base-between-controller-and-model/84645>\
**Category:** Rails\
**Created:** [February 6, 2007, 6:23pm UTC](https://www.ruby-forum.com/t/help-w-errors-add-to-base-between-controller-and-model/84645 "2007-02-06T18:23:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [February 6, 2007, 6:23pm UTC](https://www.ruby-forum.com/t/help-w-errors-add-to-base-between-controller-and-model/84645/1 "2007-02-06T18:23:01Z")

</div>

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:

if errors.size \> 0  
flash[:validation] = errors.join(’  
’)  
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:

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!

---

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [February 6, 2007, 9:34pm UTC](https://www.ruby-forum.com/t/help-w-errors-add-to-base-between-controller-and-model/84645/2 "2007-02-06T21:34:09Z")

</div>

On Feb 6, 12:23 pm, Clem R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

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

Will something like this work:

if model.save  
flash[:success] = “model successfully saved”  
else  
flash[:validate] = model.errors.full\_messages.join(“\n”)  
end

Dan M.

---

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [February 6, 2007, 10:34pm UTC](https://www.ruby-forum.com/t/help-w-errors-add-to-base-between-controller-and-model/84645/3 "2007-02-06T22:34:49Z")

</div>

Hello,

I tried using the flash[:validate] method in the model and it shows  
the “method not found” error.

What exactly does the model.save method do?

Dan M. wrote:

> On Feb 6, 12:23 pm, Clem R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Is there a way where I can route the model errors to the  
> > flash[:validate] method as I am in the controller?
> 
> Will something like this work:
> 
> if model.save  
> flash[:success] = “model successfully saved”  
> else  
> flash[:validate] = model.errors.full\_messages.join(“\n”)  
> end
> 
> Dan M.

---

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [February 6, 2007, 10:45pm UTC](https://www.ruby-forum.com/t/help-w-errors-add-to-base-between-controller-and-model/84645/4 "2007-02-06T22:45:49Z")

</div>

More on that- here’s the full errors that are displayed.

Official validation error from the model:  
Validation failed: an invitation has already been sent to  
removed\_email\_address@domain.invalid

And the other errors from the page failure:

/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/validations.rb:748:in  
`save!' #{RAILS_ROOT}/app/controllers/invite_controller.rb:40:in `bulk’  
#{RAILS\_ROOT}/app/controllers/invite\_controller.rb:30:in `bulk’

Clem R. wrote:

> Hello,
> 
> I tried using the flash[:validate] method in the model and it shows  
> the “method not found” error.
> 
> What exactly does the model.save method do?
> 
> Dan M. wrote:
> 
> > On Feb 6, 12:23 pm, Clem R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > wrote:
> > 
> > > Is there a way where I can route the model errors to the  
> > > flash[:validate] method as I am in the controller?
> > 
> > Will something like this work:
> > 
> > if model.save  
> > flash[:success] = “model successfully saved”  
> > else  
> > flash[:validate] = model.errors.full\_messages.join(“\n”)  
> > end
> > 
> > Dan M.

---

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [February 8, 2007, 7:14am UTC](https://www.ruby-forum.com/t/help-w-errors-add-to-base-between-controller-and-model/84645/5 "2007-02-08T07:14:21Z")

</div>

Dan - here’s a link to the code in pastie

[http://pastie.caboo.se/38769](http://pastie.caboo.se/38769)

Thanks for your help big time

---

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [February 7, 2007, 12:33am UTC](https://www.ruby-forum.com/t/help-w-errors-add-to-base-between-controller-and-model/84645/6 "2007-02-07T00:33:32Z")

</div>

On Feb 6, 4:34 pm, Clem R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I tried using the flash[:validate] method in the model and it shows  
> the “method not found” error.
> 
> What exactly does the model.save method do?

Can you copy and paste your model and controller action? If it’s big  
use Pastie [http://pastie.caboo.se/](http://pastie.caboo.se/) and post a link here.

Thanks,  
Dan M.
