validates_numericality_of is returning "is not a number" for everything I try. What''s up? database: column: price type: float (9,2) (I''ve also tried decimal 9,2) model: validates_numericality_of :price, :only_integer => false console: p = Product.new p.price = "3.25" p.save p.errors.to_yaml: errors: price: - is not a number I went digging through the Rails source to get the exact exception and I get: invalid value for Float(): "" The line: Kernel.Float(record.send("#{attr_name}_before_type_cast").to_s) record.send("#{attr_name}_before_type_cast").to_s # => '''' This is too basic... so I must be doing something stupid. Even updated Rails: # gem update rails Updating installed gems... Attempting remote update of rails Successfully installed rails-1.1.6 Gems: [rails] updated ...any ideas? J -- 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 -~----------~----~----~----~------~----~------~--~---
> p.price = "3.25"you are trying to set price to a string object. p.price = 3.25 or I suppose p.price = "3.25".to_f On Dec 12, 1:19 pm, "J. Riddel" <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> validates_numericality_of is returning "is not a number" for everything > I try. What''s up? > > database: > column: price > type: float (9,2) (I''ve also tried decimal 9,2) > > model: > validates_numericality_of :price, :only_integer => false > > console: > p = Product.new > p.price = "3.25" > p.save > > p.errors.to_yaml: > > errors: > price: > - is not a number > > I went digging through the Rails source to get the exact exception and I > get: > > invalid value for Float(): "" > > The line: > Kernel.Float(record.send("#{attr_name}_before_type_cast").to_s) > > record.send("#{attr_name}_before_type_cast").to_s # => '''' > > This is too basic... so I must be doing something stupid. Even updated > Rails: > > # gem update rails > Updating installed gems... > Attempting remote update of rails > Successfully installed rails-1.1.6 > Gems: [rails] updated > > ...any ideas? > > J > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
jdswift wrote:>> p.price = "3.25" > > you are trying to set price to a string object. > p.price = 3.25 > or I suppose > p.price = "3.25".to_f > > On Dec 12, 1:19 pm, "J. Riddel" <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>No, that''s not it. If you look at the code that does the conversion: Kernel.float( ... ), it takes a string argument. -- 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. Riddel wrote:> jdswift wrote: >>> p.price = "3.25" >> >> you are trying to set price to a string object. >> p.price = 3.25 >> or I suppose >> p.price = "3.25".to_f >> >> On Dec 12, 1:19 pm, "J. Riddel" <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > No, that''s not it. If you look at the code that does the conversion: > > Kernel.float( ... ), it takes a string argument.Aha, it was the flex_attributes plugin that broke it. I''ll have to email the author. -- 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 -~----------~----~----~----~------~----~------~--~---