How do I set the default value for date fields?

I want my date fields to default to NIL or “”, because the presence of a
date means something. My problem is that rails is defaulting the fields
to today’s date automatically when I create a new record through the
scaffold. I tried removing the default ‘0000-00-00’ and changing NOT
NULL to NULL, but both columns get today’s date as the default (see
below for the table’s sql syntax).

So it looks like I need to code something, but I’m unsure to put that in
the model or in the view (or if this is a form helper deal). Any help
is appreciated. Thank you in advance!

CREATE TABLE volunteers ( …other columns…
birthdate date default NULL,
competency_in_service_on date NOT NULL default ‘0000-00-00’
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

I have not tried this,
but Chapter 17 (page 361) of Agile Web D. states you can add a
:include_blank option to the date_select

HTH

Frank
----- Original Message -----
From: “Sean C.” [email protected]
To: [email protected]
Sent: Wednesday, January 04, 2006 12:39 PM
Subject: [Rails] How do I set the default value for date fields?

Thanks Frank,
I was on 371 researching partials. I’ll back track and see if that
works.

got it to work. Below is an example of the code I changed around in
app/views/admin/_form.html (Admin is the name of my controller). The
‘:include_blank => true’ is the part I added. Thanks for your help

Birthdate
<%= date_select 'volunteer', 'birthdate', :include_blank => true %></p

Frank wrote:

Glad I could help, others help me out all the time.

Frank
----- Original Message -----
From: “Sean C.” [email protected]
To: [email protected]
Sent: Wednesday, January 04, 2006 1:17 PM
Subject: [Rails] [Solved]: How do I set the default value for date
fields?

I think you can also use :prompt=>“Select Birthday” instead of
:include_blank=>true

Glad I could help, others help me out all the time.

Frank
----- Original Message -----
From: “Sean C.” [email protected]
To: [email protected]
Sent: Wednesday, January 04, 2006 1:17 PM
Subject: [Rails] [Solved]: How do I set the default value for date
fields?