# How to get a default blank for select\_date?

**URL:** <https://www.ruby-forum.com/t/how-to-get-a-default-blank-for-select-date/142534>\
**Category:** Rails\
**Created:** [July 8, 2008, 11:36pm UTC](https://www.ruby-forum.com/t/how-to-get-a-default-blank-for-select-date/142534 "2008-07-08T23:36:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@stevel](https://www.ruby-forum.com/u/stevel)\
**Post date:** [July 8, 2008, 11:36pm UTC](https://www.ruby-forum.com/t/how-to-get-a-default-blank-for-select-date/142534/1 "2008-07-08T23:36:24Z")

</div>

I’m trying to get a blank date as the default when using the  
select\_date helper as follows:

select\_date Date.today, :prefix =\> ‘startdate’, :order =\>  
[:month, :day, :year], :include\_blank =\> true

This gives me the current date as the default. It is my understanding  
(or misunderstanding) that adding the :include\_blank =\> true will  
default the values to blanks. But it doesn’t seem to be doing that.  
Although including this option does allow me to select a blank value.  
Just not defaulting to blanks, which is what I’m trying to accomplish.

Thanks in advance for any help.

Steve

---

<div class="post-metadata">

**Author:** ![stevel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@stevel](https://www.ruby-forum.com/u/stevel)\
**Post date:** [July 8, 2008, 11:39pm UTC](https://www.ruby-forum.com/t/how-to-get-a-default-blank-for-select-date/142534/2 "2008-07-08T23:39:39Z")

</div>

Instead of Date.today, pass in nil. As long as :include\_blank = true  
option  
is present, the default date will be blank.

2008/7/9 stevel [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![stevel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@stevel](https://www.ruby-forum.com/u/stevel)\
**Post date:** [July 9, 2008, 12:01am UTC](https://www.ruby-forum.com/t/how-to-get-a-default-blank-for-select-date/142534/3 "2008-07-09T00:01:04Z")

</div>

I was thinking I had to put a nil there but didn’t managed to figure  
out how to do it. I was using a plain “” which didn’t work obviously.  
I didn’t think of just using the nil variable.

Anyhow it worked.

Thank you so much.

---

<div class="post-metadata">

**Author:** ![stevel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@stevel](https://www.ruby-forum.com/u/stevel)\
**Post date:** [July 9, 2008, 2:25am UTC](https://www.ruby-forum.com/t/how-to-get-a-default-blank-for-select-date/142534/4 "2008-07-09T02:25:43Z")

</div>

FWIW–this is working for me:

f.date\_select :start\_date, :include\_blank =\> true, :order =\> [:day,  
:month, :year]

Not sure if the difference is the order of the args, or the fact that  
I’m calling date\_select vs. your select\_date. (What’s the difference  
between those 2 helpers?)

HTH,

-Roy

---

<div class="post-metadata">

**Author:** ![stevel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@stevel](https://www.ruby-forum.com/u/stevel)\
**Post date:** [July 9, 2008, 2:46am UTC](https://www.ruby-forum.com/t/how-to-get-a-default-blank-for-select-date/142534/5 "2008-07-09T02:46:41Z")

</div>

I believe date\_select requires that you specify an object and the  
method as in:  
date\_select(object\_name, method, options={})

whereas select\_date only needs a variable such as:  
select\_date( variable, option={})

when you use f.date\_select you have already defined the object  
beforehand, ( Example: \<% form\_for @object do |f| ), and hence  
your :start\_date is the method for your object f. You get the blank  
result because your :start\_date is presumably nil in the beginning.

Not sure of that answers your question or make it more confusing. 🙂

Steve
