You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a form with a text field, for which I'd like to validate the contents as numerical.
Unfortunately, properties defined with a type are typecast on assignment (this is couch_potato behavoir, I believe). So if I assign a string to a property of type Fixnum, the value is typecast (meaninglessly) to 0.
class Product
include SimplyStored::Couch
include Validatable
property :quantity, :type => Fixnum
validates_numericality_of :quantity
end
p= Product.new(:quantity => "not a number")
p.valid? # => true
p.quantity # => 0
Has anyone else come across this? Any advice on how to handle this? It seems like it might be reasonable behavior from the perspective of couch_potato, which has something like 'statically typed' attributes. But it certainly doesn't make sense in the context of validations.
The text was updated successfully, but these errors were encountered:
I've recently also run into this and the problem is as you said that CouchPotato casts on assignment. I'll see that I talk to Alex of CouchPotato. The only good place to fix this is in CouchPotato.
I have a form with a text field, for which I'd like to validate the contents as numerical.
Unfortunately, properties defined with a type are typecast on assignment (this is couch_potato behavoir, I believe). So if I assign a string to a property of type Fixnum, the value is typecast (meaninglessly) to 0.
Has anyone else come across this? Any advice on how to handle this? It seems like it might be reasonable behavior from the perspective of couch_potato, which has something like 'statically typed' attributes. But it certainly doesn't make sense in the context of validations.
The text was updated successfully, but these errors were encountered: