Forum: Ruby on Rails get # of errors in error_messages_for

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Johnroy W. (Guest)
on 2009-02-05 08:26
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....
Johnroy W. (Guest)
on 2009-02-06 04:34
Need your help RoR masters...
Julian L. (Guest)
on 2009-02-06 05:22
(Received via mailing list)
?

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
Johnroy W. (Guest)
on 2009-02-06 05:33
i need a solution my friend. any help or advice would be appreciated.
Thank you
Harold (Guest)
on 2009-02-06 06:56
(Received via mailing list)
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>
alberto (Guest)
on 2009-02-06 07:46
(Received via mailing list)
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.
Johnroy W. (Guest)
on 2009-02-06 08:10
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
This topic is locked and can not be replied to.