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:
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
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” [email protected]
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” [email protected]
No, that’s not it. If you look at the code that does the conversion:
Kernel.float( … ), it takes a string argument.
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” [email protected]
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.