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.
8d69b5f4fcc146d704dbf514157f328a?d=identicon&s=25 Johnroy World (johnroyworld)
on 2009-02-05 07: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....
8d69b5f4fcc146d704dbf514157f328a?d=identicon&s=25 Johnroy World (johnroyworld)
on 2009-02-06 03:34
Need your help RoR masters...
3131fcea0a711e5ad89c8d49cc9253b4?d=identicon&s=25 Julian Leviston (Guest)
on 2009-02-06 04: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 World
<rails-mailing-list@andreas-s.net
8d69b5f4fcc146d704dbf514157f328a?d=identicon&s=25 Johnroy World (johnroyworld)
on 2009-02-06 04:33
i need a solution my friend. any help or advice would be appreciated.
Thank you
53be54e5db4dc58e4980db5a8255621b?d=identicon&s=25 Harold (Guest)
on 2009-02-06 05:56
(Received via mailing list)
Haven't tried this, but how about

"#{User.errors.size} errors, please ..."

On Feb 5, 10:33 pm, Johnroy World <rails-mailing-l...@andreas-s.net>
47c3af2d56d44eb1d08a601c837a1262?d=identicon&s=25 alberto (Guest)
on 2009-02-06 06:46
(Received via mailing list)
On Feb 5, 1:26 am, Johnroy World <rails-mailing-l...@andreas-s.net>
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.
8d69b5f4fcc146d704dbf514157f328a?d=identicon&s=25 Johnroy World (johnroyworld)
on 2009-02-06 07:10
alberto wrote:
> On Feb 5, 1:26�am, Johnroy World <rails-mailing-l...@andreas-s.net>
> 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.