# Errors.add

**URL:** <https://www.ruby-forum.com/t/errors-add/129252>\
**Category:** Rails\
**Created:** [February 15, 2008, 7:59pm UTC](https://www.ruby-forum.com/t/errors-add/129252 "2008-02-15T19:59:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [February 15, 2008, 7:59pm UTC](https://www.ruby-forum.com/t/errors-add/129252/1 "2008-02-15T19:59:00Z")

</div>

how do i add errors manually to an object so they show up in the same  
list as the validations?

i tried errors.add - and it adds the error, but it doesn’t stop the  
object from being saved like a validates\_presence\_of would

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [February 15, 2008, 8:03pm UTC](https://www.ruby-forum.com/t/errors-add/129252/2 "2008-02-15T20:03:08Z")

</div>

Jimmy P. wrote:

> how do i add errors manually to an object so they show up in the same  
> list as the validations?
> 
> i tried errors.add - and it adds the error, but it doesn’t stop the  
> object from being saved like a validates\_presence\_of would

define your own validate() method in your model, the errors you add  
there will show up and a failure will prevent the save.

hth

ilan

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [February 15, 2008, 8:18pm UTC](https://www.ruby-forum.com/t/errors-add/129252/3 "2008-02-15T20:18:54Z")

</div>

Ilan B. wrote:

> Jimmy P. wrote:
> 
> > how do i add errors manually to an object so they show up in the same  
> > list as the validations?
> > 
> > i tried errors.add - and it adds the error, but it doesn’t stop the  
> > object from being saved like a validates\_presence\_of would
> 
> define your own validate() method in your model, the errors you add  
> there will show up and a failure will prevent the save.
> 
> hth
> 
> ilan

can you further explain how I might do this?

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [February 15, 2008, 8:39pm UTC](https://www.ruby-forum.com/t/errors-add/129252/4 "2008-02-15T20:39:10Z")

</div>

Jimmy P. wrote:

> Ilan B. wrote:
> 
> > Jimmy P. wrote:
> > 
> > > how do i add errors manually to an object so they show up in the same  
> > > list as the validations?
> > > 
> > > i tried errors.add - and it adds the error, but it doesn’t stop the  
> > > object from being saved like a validates\_presence\_of would
> > 
> > define your own validate() method in your model, the errors you add  
> > there will show up and a failure will prevent the save.
> > 
> > hth
> > 
> > ilan
> 
> can you further explain how I might do this?

class SomeModel \< ActiveRecord::Base

def validate  
errors.add(:world, “the world is not flat!”) if self.world.flat?  
end  
end

---

<div class="post-metadata">

**Author:** ![jimmypalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jimmypalmer](https://www.ruby-forum.com/u/jimmypalmer)\
**Post date:** [February 15, 2008, 8:41pm UTC](https://www.ruby-forum.com/t/errors-add/129252/5 "2008-02-15T20:41:28Z")

</div>

Ilan B. wrote:

> Jimmy P. wrote:
> 
> > Ilan B. wrote:
> > 
> > > Jimmy P. wrote:
> > > 
> > > > how do i add errors manually to an object so they show up in the same  
> > > > list as the validations?
> > > > 
> > > > i tried errors.add - and it adds the error, but it doesn’t stop the  
> > > > object from being saved like a validates\_presence\_of would
> > > 
> > > define your own validate() method in your model, the errors you add  
> > > there will show up and a failure will prevent the save.
> > > 
> > > hth
> > > 
> > > ilan
> > 
> > can you further explain how I might do this?
> 
> class SomeModel \< ActiveRecord::Base
> 
> def validate  
> errors.add(:world, “the world is not flat!”) if self.world.flat?  
> end  
> end

yeah, I tried that, but it still did not display the error and allowed  
the object to save. Do I need to manually check if there are errors and  
manually display them?
