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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs