I am trying to figure out how to customize the error messages when I use validates_presence_of. I am validating a user name and I use <%error_messages_for ''user'' %> in my view to display the messages. I know you can customize in the model with :message =>''custom message'', but I am trying to get rid of the first part of the error message which is, 1 error prohibited this user from being saved There were problems with the following fields: Is there any way to do this or is it hard coded into the rails code? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''m struggling with the same right now. Does anybody know how to do this? Thanks. Sabon On 6/10/07, Yanni Mac <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I am trying to figure out how to customize the error messages when I use > validates_presence_of. I am validating a user name and I use <%> error_messages_for ''user'' %> in my view to display the messages. I know > you can customize in the model with :message =>''custom message'', but I > am trying to get rid of the first part of the error message which is, > > 1 error prohibited this user from being saved > There were problems with the following fields: > > Is there any way to do this or is it hard coded into the rails code? > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 6/9/07, Yanni Mac <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I am trying to figure out how to customize the error messages when I use > validates_presence_of. I am validating a user name and I use <%> error_messages_for ''user'' %> in my view to display the messages. I know > you can customize in the model with :message =>''custom message'', but I > am trying to get rid of the first part of the error message which is, > > 1 error prohibited this user from being saved > There were problems with the following fields: > > Is there any way to do this or is it hard coded into the rails code?The basic idea is to look at the source for error_messages_for and then drop your own replacement into app/helpers/application_helper.rb. Here''s a *real* simple example: def error_messages_for(object_name) object = instance_variable_get("@#{object_name}") return '''' if object.errors.empty? content_tag(''ul'', object.errors.full_messages.collect {|msg| content_tag(''li'', msg)}, { :class => ''error'' }) end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---