my postgres database table was setup with
t.integer :time_employed
I had validations like so
validates :time_employed, numericality: true, allow_blank: true
and I also tried
validates_numericality_of :time_employed, allow_blank: true
But neither of them gave me the result I was looking for. I did some testing in the console and it seemed that the field was always being set to 0 or nil. If I input a string it was being set to 0.
I changed the database field to
t.string :time_employed
and now everything works like it should. It's not a huge problem, but I was hoping to keep the data correctly described by the schema.
I don't know much about databases yet, so this threw me for a loop. Can anyone explain what is happening here?
EDIT:
The problem was that it would allow blank entries, but it wouldn't throw an error if I input non numeric values. Anything would be validated as good, just not saved to the DB. After changing to t.string and no changes to the validations, it worked fine.
I also tried allow_nil: true but it had the same effect.