I am learning to use Validations and am using validates_length_of to check a field value is no longer than 240 characters. I want to be able to produce a message back to the user telling them that the value they entered was x characters too long. Does anyone know how I can work with the value and its length? validates_length_of :name, :maximum => 240, :message =>
:message => "Length is #{name.length}, max allowed is 240" 2009/5/17 phil7085 <p.jab-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org>> > I am learning to use Validations and am using validates_length_of to > check a field value is no longer than 240 characters. > > I want to be able to produce a message back to the user telling them > that the value they entered was x characters too long. > > Does anyone know how I can work with the value and its length? > > validates_length_of :name, :maximum => 240, :message => > > >--~--~---------~--~----~------------~-------~--~----~ 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 for the reply, That doesn''t give me the value for name it just gives back the name of the model. i.e Task so the length given is 4. Any ideas? On May 17, 10:43 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> :message => "Length is #{name.length}, max allowed is 240" > > 2009/5/17 phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> > > > > > I am learning to use Validations and am using validates_length_of to > > check a field value is no longer than 240 characters. > > > I want to be able to produce a message back to the user telling them > > that the value they entered was x characters too long. > > > Does anyone know how I can work with the value and its length? > > > validates_length_of :name, :maximum => 240, :message =>
On May 17, 1:17 pm, phil7085 <philip.ben...-2m9ZUH0h1mlCxZSNXjsOBw@public.gmane.org> wrote:> Thanks for the reply, That doesn''t give me the value for name it just > gives back the name of the model. i.e Task so the length given is 4. > > Any ideas?you could do this with a custom validation, ie validates do |record| if ... record.errors.add :name, "Name is #{record.name.length} characters long" end end> > On May 17, 10:43 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > :message => "Length is #{name.length}, max allowed is 240" > > > 2009/5/17 phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> > > > > I am learning to use Validations and am using validates_length_of to > > > check a field value is no longer than 240 characters. > > > > I want to be able to produce a message back to the user telling them > > > that the value they entered was x characters too long. > > > > Does anyone know how I can work with the value and its length? > > > > validates_length_of :name, :maximum => 240, :message =>
2009/5/17 phil7085 <philip.benton-2m9ZUH0h1mlCxZSNXjsOBw@public.gmane.org>> > > Thanks for the reply, That doesn''t give me the value for name it just > gives back the name of the model. i.e Task so the length given is 4.That''s true, I would go with Frederick''s solution. Colin> > > Any ideas? > > > > On May 17, 10:43 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > :message => "Length is #{name.length}, max allowed is 240" > > > > 2009/5/17 phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> > > > > > > > > > I am learning to use Validations and am using validates_length_of to > > > check a field value is no longer than 240 characters. > > > > > I want to be able to produce a message back to the user telling them > > > that the value they entered was x characters too long. > > > > > Does anyone know how I can work with the value and its length? > > > > > validates_length_of :name, :maximum => 240, :message => > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yep that works, not quite sure why i couldn''t access the length before though, still abit over my head but i''m learning. Thanks for your help guys. P On May 17, 2:06 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/5/17 phil7085 <philip.ben...-2m9ZUH0h1mlCxZSNXjsOBw@public.gmane.org> > > > > > Thanks for the reply, That doesn''t give me the value for name it just > > gives back the name of the model. i.e Task so the length given is 4. > > That''s true, I would go with Frederick''s solution. > Colin > > > > > Any ideas? > > > On May 17, 10:43 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > :message => "Length is #{name.length}, max allowed is 240" > > > > 2009/5/17 phil7085 <p....-LfUFBbCNao6Ide+eSLyLAQ@public.gmane.org> > > > > > I am learning to use Validations and am using validates_length_of to > > > > check a field value is no longer than 240 characters. > > > > > I want to be able to produce a message back to the user telling them > > > > that the value they entered was x characters too long. > > > > > Does anyone know how I can work with the value and its length? > > > > > validates_length_of :name, :maximum => 240, :message =>