# Validates\_numericality\_of simply not working

**URL:** <https://www.ruby-forum.com/t/validates-numericality-of-simply-not-working/79099>\
**Category:** Rails\
**Created:** [December 12, 2006, 4:19am UTC](https://www.ruby-forum.com/t/validates-numericality-of-simply-not-working/79099 "2006-12-12T04:19:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JSRiddel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc348/32.png) [@JSRiddel](https://www.ruby-forum.com/u/JSRiddel)\
**Post date:** [December 12, 2006, 4:19am UTC](https://www.ruby-forum.com/t/validates-numericality-of-simply-not-working/79099/1 "2006-12-12T04:19:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JSRiddel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc348/32.png) [@JSRiddel](https://www.ruby-forum.com/u/JSRiddel)\
**Post date:** [December 12, 2006, 6:45am UTC](https://www.ruby-forum.com/t/validates-numericality-of-simply-not-working/79099/2 "2006-12-12T06:45:24Z")

</div>

> 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” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![JSRiddel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc348/32.png) [@JSRiddel](https://www.ruby-forum.com/u/JSRiddel)\
**Post date:** [December 12, 2006, 6:58am UTC](https://www.ruby-forum.com/t/validates-numericality-of-simply-not-working/79099/3 "2006-12-12T06:58:23Z")

</div>

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” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

No, that’s not it. If you look at the code that does the conversion:

Kernel.float( … ), it takes a string argument.

---

<div class="post-metadata">

**Author:** ![JSRiddel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc348/32.png) [@JSRiddel](https://www.ruby-forum.com/u/JSRiddel)\
**Post date:** [December 12, 2006, 7:33am UTC](https://www.ruby-forum.com/t/validates-numericality-of-simply-not-working/79099/4 "2006-12-12T07:33:33Z")

</div>

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” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> 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.
