Is there any plugin which validates amount?? say the amount entered should be greater than 0. Thanks =] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
#### Taken From Agile Web Development With Rails, 2nd Ed. p.369 #### validates_length_of Validates that the length of the value of each of the attributes meets some constraint: at least a given length, at most a given length, between two lengths, or exactly a given length. Rather than having a single :message option, this validator allows separate mes- sages for dif ferent validation failures, although :message may still be used. In all options, the lengths may not be negative. ## EXAMPLES ## validates_length_of :name, :maximum => 50 validates_length_of :password, :in => 6..20 validates_length_of :address, :minimum => 10, :message => "seems too short" end On Sep 24, 6:44 am, zephyr <spongebo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is there any plugin which validates amount?? say the amount entered > should be greater than 0. > > Thanks =]--~--~---------~--~----~------------~-------~--~----~ 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_lenght_of is meant for strings, it can behave unexpected when used on integer attributes as it uses byte comparison ... On 24 Sep., 15:30, ebrad <nisguy_...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> #### Taken From Agile Web Development With Rails, 2nd Ed. p.369 #### > > validates_length_of > > Validates that the length of the value of each of the attributes meets > some constraint: > at least a given length, at most a given length, between two lengths, > or exactly a given > length. Rather than having a single :message option, this validator > allows separate mes- > sages for dif ferent validation failures, although :message may still > be used. In all options, > the lengths may not be negative. > > ## EXAMPLES ## > > validates_length_of :name, :maximum => 50 > validates_length_of :password, :in => 6..20 > validates_length_of :address, :minimum => 10, > :message => "seems too short" > end > > On Sep 24, 6:44 am, zephyr <spongebo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Is there any plugin which validates amount?? say the amount entered > > should be greater than 0. > > > Thanks =]- Zitierten Text ausblenden - > > - Zitierten Text anzeigen ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
This is covered in the agile book. You need to write your own validation. def validate errors.add :price, "must be greater than 0" unless self.price > 0 end That''s a quickie off the top of my head. You may want to only do that check if the value is filled in (self.price.blank?). That''s up to you. On 9/24/07, zephyr <spongebob12-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Is there any plugin which validates amount?? say the amount entered > should be greater than 0. > > Thanks =] > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 must not have read his post carefully enough. On Sep 24, 9:39 am, Thorsten <duple...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> validates_lenght_of is meant for strings, it can behave unexpected > when used on integer attributes as it uses byte comparison ... > > On 24 Sep., 15:30, ebrad <nisguy_...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > #### Taken From Agile Web Development With Rails, 2nd Ed. p.369 #### > > > validates_length_of > > > Validates that the length of the value of each of the attributes meets > > some constraint: > > at least a given length, at most a given length, between two lengths, > > or exactly a given > > length. Rather than having a single :message option, this validator > > allows separate mes- > > sages for dif ferent validation failures, although :message may still > > be used. In all options, > > the lengths may not be negative. > > > ## EXAMPLES ## > > > validates_length_of :name, :maximum => 50 > > validates_length_of :password, :in => 6..20 > > validates_length_of :address, :minimum => 10, > > :message => "seems too short" > > end > > > On Sep 24, 6:44 am, zephyr <spongebo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Is there any plugin which validates amount?? say the amount entered > > > should be greater than 0. > > > > Thanks =]- Zitierten Text ausblenden - > > > - Zitierten Text anzeigen ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Go look at the online Rails docs, and click on "Show source" for the validates_blah functions. They are pretty straightforward. -- 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. this helps =] On Sep 24, 9:51 pm, "Brian Hogan" <bpho...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This is covered in the agile book. You need to write your own validation. > > def validate > errors.add :price, "must be greater than 0" unless self.price > 0 > end > > That''s a quickie off the top of my head. You may want to only do that check > if the value is filled in (self.price.blank?). That''s up to you. > > On 9/24/07, zephyr <spongebo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Is there any plugin which validates amount?? say the amount entered > > should be greater than 0. > > > Thanks =]--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---