Kris
2006-Aug-16 05:44 UTC
[Rails] validates_presence_of non-null float/boolean/integer fields
Has anyone figured out a way to get validates_presence_of to work with float, boolean, and integer fields that are defined as non-null in the schema? The problem is, ruby intializes these types to the default schema value, which for mysql is never null if the column is not allowed to be null, and as a result they are initialized in the form with a value, and are never null. I found a work around for integers that requires a nasty method override in the ActiveRecord class that sets the default values from the database, but I can not find a solution to do the same for floats because ruby will not let me assign a float to null once it has been initialized with a value. Any thoughts? Thanks, Kris -- Posted via http://www.ruby-forum.com/.
Apparently Analagous Threads
- boolean db fields set to false fail validation with validates_presence_of?
- validates_presence_of fails with false boolean
- validates_presence_of fields. in parent ok, but how in children?
- How to restore fields ("validates_presence_of")
- Having problem with validates_presence_of fields in form when trying to also use ActiveScaffold (x-posted at ActiveScaffold group)