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 ; -- Posted via http://www.ruby-forum.com/.
I have not tried this, but Chapter 17 (page 361) of Agile Web Development states you can add a :include_blank option to the date_select HTH Frank ----- Original Message ----- From: "Sean Clark" <smc7000@gmail.com> To: <rails@lists.rubyonrails.org> Sent: Wednesday, January 04, 2006 12:39 PM Subject: [Rails] 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 ; > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Sean Clark
2006-Jan-04 18:06 UTC
[Rails] Re: 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. -- Posted via http://www.ruby-forum.com/.
Sean Clark
2006-Jan-04 18:17 UTC
[Rails] [Solved]: How do I set the default value for date fields?
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 <p><label for="volunteer_birthdate">Birthdate</label><br/> <%= date_select ''volunteer'', ''birthdate'', :include_blank => true %></p -- Posted via http://www.ruby-forum.com/.
Frank
2006-Jan-04 18:23 UTC
[Rails] [Solved]: How do I set the default value for date fields?
Glad I could help, others help me out all the time. Frank ----- Original Message ----- From: "Sean Clark" <smc7000@gmail.com> To: <rails@lists.rubyonrails.org> Sent: Wednesday, January 04, 2006 1:17 PM Subject: [Rails] [Solved]: How do I set the default value for date fields?> 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 > > <p><label for="volunteer_birthdate">Birthdate</label><br/> > <%= date_select ''volunteer'', ''birthdate'', :include_blank => true %></p > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Kevin Olbrich
2006-Jan-04 18:54 UTC
[Rails] Re: [Solved]: How do I set the default value for date fields
Frank wrote:> Glad I could help, others help me out all the time. > > Frank > ----- Original Message ----- > From: "Sean Clark" <smc7000@gmail.com> > To: <rails@lists.rubyonrails.org> > 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 -- Posted via http://www.ruby-forum.com/.