Hi, In code like this validates_numericality_of :price the price is supposed to be a string in number format but can include other non-digital characters like ''a'', since :only_integer is set to false by default, right? In rails implementation, it use Kernel.Float to complete the work. But seems Kernel.Float(ruby 1.8.6) always throw an exception when the number string contains non-digital characters, such as "123.00a". So in fact there is no diffierences whether the switch :only_integer is turned on or off. I found in JRuby, the Kernel.Float will accept string that looks like "123.00a" but will finally return a zero. Do I misunderstand of the :only_integer switch? Thanks, Jan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
only_integer means it will only allow integers. Otherwise, decimal places are allowed. You will need to write a custom method to validate the "numericality" of strings containing alpha characters. On Nov 30, 2:21 am, Jan <jan.h....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > In code like this > > validates_numericality_of :price > > the price is supposed to be a string in number format but can include > other non-digital characters like ''a'', since :only_integer is set to > false by default, right? > > In rails implementation, it use Kernel.Float to complete the work. But > seems Kernel.Float(ruby 1.8.6) always throw an exception when the > number string contains non-digital characters, such as "123.00a". So > in fact there is no diffierences whether the switch :only_integer is > turned on or off. > > I found in JRuby, the Kernel.Float will accept string that looks like > "123.00a" but will finally return a zero. > > Do I misunderstand of the :only_integer switch? > > Thanks, > Jan--~--~---------~--~----~------------~-------~--~----~ 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 Nov 30, 2007, at 1:21 AM, Jan wrote:> In code like this > > validates_numericality_of :price > > the price is supposed to be a string in number format but can include > other non-digital characters like ''a'', since :only_integer is set to > false by default, right? > > In rails implementation, it use Kernel.Float to complete the work. But > seems Kernel.Float(ruby 1.8.6) always throw an exception when the > number string contains non-digital characters, such as "123.00a". So > in fact there is no diffierences whether the switch :only_integer is > turned on or off. > > I found in JRuby, the Kernel.Float will accept string that looks like > "123.00a" but will finally return a zero. > > Do I misunderstand of the :only_integer switch?Integer would mean 100 vs 100.0 I''m new to Ruby, so maybe there''s something unique, but why would you think 123.00a is a float? [123, 123.00, -123.00].each do |n| puts n.is_a?(Float) end #false #true #true Trying to put in a number like 123.00a in that array makes it fail. -- def gw acts_as_n00b writes_at(www.railsdev.ws) end --~--~---------~--~----~------------~-------~--~----~ 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 Guys, I got the meaning of only_integer. I found I was misleaded by JRuby''s implementation of Kernel.Float - maybe it''s a bug of JRuby ... On Nov 30, 5:45 pm, Greg Willits <li...-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote:> On Nov 30, 2007, at 1:21 AM, Jan wrote: > > > > > In code like this > > > validates_numericality_of :price > > > the price is supposed to be a string in number format but can include > > other non-digital characters like ''a'', since :only_integer is set to > > false by default, right? > > > In rails implementation, it use Kernel.Float to complete the work. But > > seems Kernel.Float(ruby 1.8.6) always throw an exception when the > > number string contains non-digital characters, such as "123.00a". So > > in fact there is no diffierences whether the switch :only_integer is > > turned on or off. > > > I found in JRuby, the Kernel.Float will accept string that looks like > > "123.00a" but will finally return a zero. > > > Do I misunderstand of the :only_integer switch? > > Integer would mean 100 vs 100.0 > > I''m new to Ruby, so maybe there''s something unique, but why would you > think 123.00a is a float? > > [123, 123.00, -123.00].each do |n| > puts n.is_a?(Float) > end > > #false > #true > #true > > Trying to put in a number like 123.00a in that array makes it fail. > > -- > def gw > acts_as_n00b > writes_at(www.railsdev.ws) > end--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---