Inserting NULL values into PostgreSQL from Rails

I have several TIME columns in a PostgreSQL table that I am trying to
store times of day in. These columns allow NULL values since there
may some records where there is no time to store.

My problem is that Rails is inserting a default value into these
fields (the result of calling regardless of the value that
is passed from a form. I am generating select tags with possible time
values, and I have added one additional one called ‘none’ which I
want to insert a NULL value. I have tried all kinds of values for
this option tag, and even tried writing a attribute_before_type_cast
function and calling it via before_save to try and reset the value to
null or nil. I have had no luck.

So I am pretty sure that I am missing something- what do I have to do
to get Rails to allow an attribute to hold a NULL value and also
allow me to insert one into the database?


You have to do it by hand. At present, rails does not respect nulls
for any but numeric data.

Seems pretty basic. This is 1.0, though…

On 1/31/06, Jim B. [email protected] wrote:

function and calling it via before_save to try and reset the value to

"Her faults were those of her race and sex; her virtues were her own.
Farewell, and if for ever - "

– “Travels with a Donkey in the Cevennes” by Robert Louis Stevenson

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