# Check if error\_messages\_for contains special error

**URL:** <https://www.ruby-forum.com/t/check-if-error-messages-for-contains-special-error/137481>\
**Category:** Rails\
**Created:** [May 13, 2008, 4:17pm UTC](https://www.ruby-forum.com/t/check-if-error-messages-for-contains-special-error/137481 "2008-05-13T16:17:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dummschwaetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e480ec/32.png) [@dummschwaetz](https://www.ruby-forum.com/u/dummschwaetz)\
**Post date:** [May 13, 2008, 4:17pm UTC](https://www.ruby-forum.com/t/check-if-error-messages-for-contains-special-error/137481/1 "2008-05-13T16:17:02Z")

</div>

Hi,  
im realy new to ror, so my question may be stupid:  
in the controller I check if a person who wants to register ist older  
than 18 years. If the person isn’t I add an error with  
errors.add\_to\_base($USER\_ERROR\_VOLLJAEHRIG).  
I’m having trouble with the validation of each select field that is  
provided by date\_select, because I can’t get each selectfield red if it  
is empty.  
So I thought to put the background of the div that contains the  
date-select-fields into red. How can I check if error\_messages\_for  
contains the message that I addes with errors.add\_to\_base?  
Think this is not a nice way. Maby you hav an other solution?

thanks in advance

---

<div class="post-metadata">

**Author:** ![dummschwaetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e480ec/32.png) [@dummschwaetz](https://www.ruby-forum.com/u/dummschwaetz)\
**Post date:** [May 21, 2008, 10:49pm UTC](https://www.ruby-forum.com/t/check-if-error-messages-for-contains-special-error/137481/2 "2008-05-21T22:49:22Z")

</div>

On 5/13/08, Kim Q. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> in the controller I check if a person who wants to register ist older  
> than 18 years. If the person isn’t I add an error with  
> errors.add\_to\_base($USER\_ERROR\_VOLLJAEHRIG).  
> I’m having trouble with the validation of each select field that is  
> provided by date\_select, because I can’t get each selectfield red if it  
> is empty.

You only need to make a validation in the model for the date field.  
Rails handles the fact that date\_select is seperate fields in the  
view.

validates\_presence\_of :my\_date

> So I thought to put the background of the div that contains the  
> date-select-fields into red. How can I check if error\_messages\_for  
> contains the message that I addes with errors.add\_to\_base?  
> Think this is not a nice way. Maby you hav an other solution?

I’ve never use add\_to\_base myself, I always want the error to be  
associated with the field that caused it.

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)
