Hi all, I was wondering if it was possible to globally change the Rails validation error messages? For example, when I enter a blank field I get the message: "Caption can''t be blank" I''d like for blank fields to show "Caption is a mandatory field" I know I can give each validation a custom error message, but I''d like to change it globally. Cheers, Diego --~--~---------~--~----~------------~-------~--~----~ 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 got a hack. Somewhere in enviornment.rb set a bunch of global variables with your custom error messages. Then in each model, set the error message to the global variable. If you go to http://dev.subimage.com/projects/substruct and look at the CVS, you can see it done there. David --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Diego, you can simply add the following to your validation: :message => "My validation message." e.g. validates_presence_of :name, :message => "Name field cannot be blank." Good luck, -Conrad On 2/26/07, Diego <dbarros-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, > > I was wondering if it was possible to globally change the Rails > validation error messages? > > For example, when I enter a blank field I get the message: > > "Caption can''t be blank" > > I''d like for blank fields to show > > "Caption is a mandatory field" > > I know I can give each validation a custom error message, but I''d like > to change it globally. > > Cheers, > Diego > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
validates_presence_of :caption, :message => "is a mandatory field" Don''t add the field name as part of the message because it gets added to the attribute already as errors#each_full [which is what normally gets called IIRC]. Even if you write your own error message handling you''re better off not adding the attribute name and just using errors#each_full. YMMV RSL On 2/27/07, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Hey Diego, you can simply add the following to your validation: > > :message => "My validation message." > > e.g. > > validates_presence_of :name, :message => "Name field cannot be blank." > > Good luck, > > -Conrad > > On 2/26/07, Diego <dbarros-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi all, > > > > I was wondering if it was possible to globally change the Rails > > validation error messages? > > > > For example, when I enter a blank field I get the message: > > > > "Caption can''t be blank" > > > > I''d like for blank fields to show > > > > "Caption is a mandatory field" > > > > I know I can give each validation a custom error message, but I''d like > > to change it globally. > > > > Cheers, > > Diego > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Russell and all others for taking the time to reply. I will give these a try. On Feb 28, 1:18 am, "Russell Norris" <sco...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> validates_presence_of :caption, :message => "is a mandatory field" > > Don''t add the field name as part of the message because it gets added to the > attribute already as errors#each_full [which is what normally gets called > IIRC]. Even if you write your own error message handling you''re better off > not adding the attribute name and just using errors#each_full. YMMV > > RSL > > On 2/27/07, Conrad Taylor <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hey Diego, you can simply add the following to your validation: > > > :message => "My validation message." > > > e.g. > > > validates_presence_of :name, :message => "Name field cannot be blank." > > > Good luck, > > > -Conrad > > > On 2/26/07, Diego <dbar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi all, > > > > I was wondering if it was possible to globally change the Rails > > > validation error messages? > > > > For example, when I enter a blank field I get the message: > > > > "Caption can''t be blank" > > > > I''d like for blank fields to show > > > > "Caption is a mandatory field" > > > > I know I can give each validation a custom error message, but I''d like > > > to change it globally. > > > > Cheers, > > > Diego--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---