Forum: Ruby on Rails Inserting NULL values into PostgreSQL from Rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7b221126deb35b09f2673d2531d4219a?d=identicon&s=25 Jim Benton (Guest)
on 2006-01-31 01:06
(Received via mailing list)
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 Time.new) 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?

Thanks.
8ed6d55dddf47e0974bac833f08e4390?d=identicon&s=25 Ian Harding (Guest)
on 2006-01-31 15:15
(Received via mailing list)
You have to do it by hand.  At present, rails does not respect nulls
for any but numeric data.

http://dev.rubyonrails.org/ticket/3301

Seems pretty basic.  This is 1.0, though...

On 1/31/06, Jim Benton <theman@infiniteexpanse.net> wrote:
> function and calling it via before_save to try and reset the value to
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
"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 topic is locked and can not be replied to.