Get # of errors in error_messages_for


#1

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…


#2

Need your help RoR masters…


#3

?

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

On 06/02/2009, at 1:34 PM, Johnroy W.
<removed_email_address@domain.invalid


#4

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


#5

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


#6

alberto wrote:

On Feb 5, 1:26�am, Johnroy W. 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


#7

On Feb 5, 1:26 am, Johnroy W. 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.