# Get # of errors in error\_messages\_for

**URL:** <https://www.ruby-forum.com/t/get-of-errors-in-error-messages-for/159507>\
**Category:** Rails\
**Created:** [February 5, 2009, 7:26am UTC](https://www.ruby-forum.com/t/get-of-errors-in-error-messages-for/159507 "2009-02-05T07:26:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnroyworld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bcef8e/32.png) [@johnroyworld](https://www.ruby-forum.com/u/johnroyworld)\
**Post date:** [February 5, 2009, 7:26am UTC](https://www.ruby-forum.com/t/get-of-errors-in-error-messages-for/159507/1 "2009-02-05T07:26:40Z")

</div>

hi everyone here i go again, i have problem we error message validation  
here is the sample of my code:

error\_messages\_for :user, :header\_message =\> ‘X errors, please find red  
mark’, :message =\> ‘Following errors were found:’

the problem is that how where going to get the value “X errors” or the  
number of errors if they have when the is submitted.

I like the idea of the default error message that have a counter of  
errors like for example “2 errors prohibited this user from being  
saved”. My purpose is to make my own error message but the idea of  
displaying the number of errors is my problem. Please help me on how to  
do it. Thank you in advance…

---

<div class="post-metadata">

**Author:** ![johnroyworld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bcef8e/32.png) [@johnroyworld](https://www.ruby-forum.com/u/johnroyworld)\
**Post date:** [February 6, 2009, 3:34am UTC](https://www.ruby-forum.com/t/get-of-errors-in-error-messages-for/159507/2 "2009-02-06T03:34:56Z")

</div>

Need your help RoR masters…

---

<div class="post-metadata">

**Author:** ![johnroyworld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bcef8e/32.png) [@johnroyworld](https://www.ruby-forum.com/u/johnroyworld)\
**Post date:** [February 6, 2009, 4:22am UTC](https://www.ruby-forum.com/t/get-of-errors-in-error-messages-for/159507/3 "2009-02-06T04:22:13Z")

</div>

?

Blog: [http://random8.zenunit.com/](http://random8.zenunit.com/)  
Learn rails: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)

On 06/02/2009, at 1:34 PM, Johnroy W.  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![johnroyworld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bcef8e/32.png) [@johnroyworld](https://www.ruby-forum.com/u/johnroyworld)\
**Post date:** [February 6, 2009, 4:33am UTC](https://www.ruby-forum.com/t/get-of-errors-in-error-messages-for/159507/4 "2009-02-06T04:33:50Z")

</div>

i need a solution my friend. any help or advice would be appreciated.  
Thank you

---

<div class="post-metadata">

**Author:** ![johnroyworld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bcef8e/32.png) [@johnroyworld](https://www.ruby-forum.com/u/johnroyworld)\
**Post date:** [February 6, 2009, 5:56am UTC](https://www.ruby-forum.com/t/get-of-errors-in-error-messages-for/159507/5 "2009-02-06T05:56:21Z")

</div>

Haven’t tried this, but how about

“#{User.errors.size} errors, please …”

On Feb 5, 10:33 pm, Johnroy W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![johnroyworld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bcef8e/32.png) [@johnroyworld](https://www.ruby-forum.com/u/johnroyworld)\
**Post date:** [February 6, 2009, 7:10am UTC](https://www.ruby-forum.com/t/get-of-errors-in-error-messages-for/159507/6 "2009-02-06T07:10:39Z")

</div>

alberto wrote:

> On Feb 5, 1:26ï¿½am, Johnroy W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > error\_messages\_for :user, :header\_message =\> ‘X errors, please find red  
> > mark’, :message =\> ‘Following errors were found:’
> 
> @user.errors.full\_messages
> 
> that will return an array of the text messages. So you can do  
> @user.errors.full\_messages.size and then iterate on them to create  
> your own error message.

nice one know i know, thanks a lot, your the man… keep up the good work

---

<div class="post-metadata">

**Author:** ![johnroyworld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bcef8e/32.png) [@johnroyworld](https://www.ruby-forum.com/u/johnroyworld)\
**Post date:** [February 6, 2009, 6:46am UTC](https://www.ruby-forum.com/t/get-of-errors-in-error-messages-for/159507/7 "2009-02-06T06:46:01Z")

</div>

On Feb 5, 1:26 am, Johnroy W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> error\_messages\_for :user, :header\_message =\> ‘X errors, please find red  
> mark’, :message =\> ‘Following errors were found:’

@user.errors.full\_messages

that will return an array of the text messages. So you can do  
@user.errors.full\_messages.size and then iterate on them to create  
your own error message.
