Hello, I''m trying to cut down the errors if the guy already getting the empty nickname, so he doesn''t get anything about the nickname is short. validates_presence_of :nickname This below is not working ? validates_length_of :nickname, :within => 4..40, :if => Proc.new { |user| user.nickname.length > 1 } nor this one below? validates_length_of :nickname, :within => 4..40, :if => nickname.length> 1Anyone have a solution for this? Thanks :) -- 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 -~----------~----~----~----~------~----~------~--~---
validates_presence_of :nickname validates_length_of :nickname, :in => 4..40, :allow_nil => true but just make sure that you change the nickname param from "" [empty string] to nil or it won''t work. "".nil? => false. I dunno why there''s not a :allow_blank => true which could cover nil? and empty? RSL On 3/29/07, Jamal Soueidan <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hello, > > I''m trying to cut down the errors if the guy already getting the empty > nickname, so he doesn''t get anything about the nickname is short. > > validates_presence_of :nickname > > This below is not working ? > > validates_length_of :nickname, :within => 4..40, :if => Proc.new { > |user| user.nickname.length > 1 } > > nor this one below? > > validates_length_of :nickname, :within => 4..40, :if => nickname.length > > 1 > > Anyone have a solution for this? > > Thanks :) > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Russell Norris wrote:> validates_presence_of :nickname > validates_length_of :nickname, :in => 4..40, :allow_nil => true > > but just make sure that you change the nickname param from "" [empty > string] > to nil or it won''t work. "".nil? => false. I dunno why there''s not a > :allow_blank => true which could cover nil? and empty? > > RSLHmm, thats kind of weird, in the Web Development with Rails the book give a example to this. validates_length_of :nickname, :in => 4..40, :if => Proc.new {|u| u.nickname.blank? But this are not working? Your example are not working either, it gives me "undefined local variable or method ''allow_nil''" ? -- 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 -~----------~----~----~----~------~----~------~--~---
Perhaps you have other errors? I dunno how else to help. Here''s the API page for validates_length_of which clearly states that :allow_nil is a valid parameter. http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000942 Sigh. RSL On 3/29/07, Jamal Soueidan <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Russell Norris wrote: > > validates_presence_of :nickname > > validates_length_of :nickname, :in => 4..40, :allow_nil => true > > > > but just make sure that you change the nickname param from "" [empty > > string] > > to nil or it won''t work. "".nil? => false. I dunno why there''s not a > > :allow_blank => true which could cover nil? and empty? > > > > RSL > > Hmm, thats kind of weird, in the Web Development with Rails the book > give a example to this. > > validates_length_of :nickname, :in => 4..40, :if => Proc.new {|u| > u.nickname.blank? > > But this are not working? > > Your example are not working either, it gives me "undefined local > variable or method ''allow_nil''" ? > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Russell Norris wrote:> Perhaps you have other errors? I dunno how else to help. Here''s the API > page > for validates_length_of which clearly states that :allow_nil is a valid > parameter. > > http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000942 > > Sigh. > > RSLYeah, I''m wondering about that too! Kind of weird :( But thanks for your help :D -- 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 -~----------~----~----~----~------~----~------~--~---