Hi all, I have the some fields being validated on my model and if the validation fails I can override the Message by using :message but how can I override the field name that apears on the messge: Intead of password is too long -> where "is too long" i can set in message bu I want the message to be "field_1 is too long" Thnaks, -- 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 Feb 12, 2:09 pm, "J. mp" <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have the some fields being validated on my model and if the validation > fails I can override the Message by using :message but how can I > override the field name that apears on the messge: > Intead of password is too long -> where "is too long" i can set in > message > bu I want the message to be > "field_1 is too long"You could specify an arbitrary attribute name to ActiveRecord::Errors#add. Arguably, this is an abuse of the API and may not work in future releases of ActiveRecord. Alternatively, use ActiveRecord::Errors#add_to_base to add a message to the base object instead of a specific attribute. This gives you control of the full error message. Finally, you could use a localization plugin to handle translation of error messages in the view. Ciao, Sheldon. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
http://www.agilewebdevelopment.com/plugins/custom_error_message ed On 2/12/07, Sheldon Hearn <sheldonh-Uqlk7TKVmMlWaveUIWBRJg@public.gmane.org> wrote:> > > > On Feb 12, 2:09 pm, "J. mp" <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > I have the some fields being validated on my model and if the validation > > fails I can override the Message by using :message but how can I > > override the field name that apears on the messge: > > Intead of password is too long -> where "is too long" i can set in > > message > > bu I want the message to be > > "field_1 is too long" > > You could specify an arbitrary attribute name to > ActiveRecord::Errors#add. Arguably, this is an abuse of the API and > may not work in future releases of ActiveRecord. > > Alternatively, use ActiveRecord::Errors#add_to_base to add a message > to the base object instead of a specific attribute. This gives you > control of the full error message. > > Finally, you could use a localization plugin to handle translation of > error messages in the view. > > Ciao, > Sheldon. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ed Hickey wrote:> http://www.agilewebdevelopment.com/plugins/custom_error_message > > edI use this and love it. -- 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 -~----------~----~----~----~------~----~------~--~---
Alex Wayne wrote:> Ed Hickey wrote: >> http://www.agilewebdevelopment.com/plugins/custom_error_message >> >> ed > > I use this and love it.Could not found any documentation for http://www.agilewebdevelopment.com/plugins/custom_error_message Regarding the Sheldon 2nd proposal:>Alternatively, use ActiveRecord::Errors#add_to_base to add a message >to the base object instead of a specific attribute. This gives you >control of the full error message.Can I do this per attribute, how would I do that? Must I have my own validation methods and not rely on Ruby validates_ methods? -- 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 -~----------~----~----~----~------~----~------~--~---
J. mp wrote:> Alex Wayne wrote: >> Ed Hickey wrote: >>> http://www.agilewebdevelopment.com/plugins/custom_error_message >>> >>> ed >> >> I use this and love it. > > Could not found any documentation for > http://www.agilewebdevelopment.com/plugins/custom_error_message > > Regarding the Sheldon 2nd proposal: >>Alternatively, use ActiveRecord::Errors#add_to_base to add a message >>to the base object instead of a specific attribute. This gives you >>control of the full error message. > > Can I do this per attribute, how would I do that? Must I have my own > validation methods and not rely on Ruby validates_ methods?From the missing answers on this topic I assume that Rails haven''t a flexible solution for my problem. I have to rely on plugins or rely on my own validations. Am I right? Anyway, can someone provide-me docs or sample for http://www.agilewebdevelopment.com/plugins/custom_error_message If it lacks documentation, I wouldn''t mind to write a bit about it, but I need a starting point. -- 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 -~----------~----~----~----~------~----~------~--~---
it doesn''t lack documentation - see the README file inccluded in the
plugin:
Custom Error Message
===================
This plugin gives you the option to not have your custom validation error
message
prefixed with the attribute name. Ordinarily, if you have, say:
    validates_acceptance_of :accepted_terms, :message => ''Please
accept the
terms of service''
You''ll get the following error message:
    Accepted terms Please accept the terms of service
This plugin allows you to omit the attribute name for specific messages. All
you have to do
is begin the message with a ''^'' character. Example:
    validates_acceptance_of :accepted_terms, :message => ''^Please
accept the
terms of service''
Detail
------
Redefines the ActiveRecord::Errors::full_messages method:
 Returns all the full error messages in an array. ''Base''
messages are
handled as usual.
 Non-base messages are prefixed with the attribute name as usual UNLESS they
begin with ''^''
 in which case the attribute name is omitted.
On 2/13/07, J. mp
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> J. mp wrote:
> > Alex Wayne wrote:
> >> Ed Hickey wrote:
> >>>
http://www.agilewebdevelopment.com/plugins/custom_error_message
> >>>
> >>> ed
> >>
> >> I use this and love it.
> >
> > Could not found any documentation for
> > http://www.agilewebdevelopment.com/plugins/custom_error_message
> >
> > Regarding the Sheldon 2nd proposal:
> >>Alternatively, use ActiveRecord::Errors#add_to_base to add a
message
> >>to the base object instead of a specific attribute.  This gives you
> >>control of the full error message.
> >
> > Can I do this per attribute, how would I do that?  Must I have my own
> > validation methods and not rely on Ruby validates_ methods?
>
> From the missing answers on this topic I assume that Rails haven''t
a
> flexible solution for my problem. I have to rely on plugins or rely on
> my own validations. Am I right?
> Anyway, can someone provide-me docs or sample for
> http://www.agilewebdevelopment.com/plugins/custom_error_message
> If it lacks documentation, I wouldn''t mind to write a bit about
it, but
> I need a starting point.
>
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---
Thanks a lot all for the help, it is very useful -- 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 -~----------~----~----~----~------~----~------~--~---
J. mp wrote:> > Thanks a lot all for the help, it is very usefulJust one more question. I have no experience in how to install plugins. How can I install this? (sorry for my newbie kink of questions, but is becuse I''m getting started with ruby on rails) -- 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 -~----------~----~----~----~------~----~------~--~---