# How to get date\_select to default to unused date?

**URL:** <https://www.ruby-forum.com/t/how-to-get-date-select-to-default-to-unused-date/171054>\
**Category:** Rails\
**Created:** [June 25, 2009, 9:26pm UTC](https://www.ruby-forum.com/t/how-to-get-date-select-to-default-to-unused-date/171054 "2009-06-25T21:26:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dansinker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/65b543/32.png) [@dansinker](https://www.ruby-forum.com/u/dansinker)\
**Post date:** [June 25, 2009, 9:26pm UTC](https://www.ruby-forum.com/t/how-to-get-date-select-to-default-to-unused-date/171054/1 "2009-06-25T21:26:55Z")

</div>

I’ve got a simple form that uses date\_select and I’d love to have it  
automatically choose the next open date (bonus points: have it skip  
weekends). How would I do this?

Thanks so much!

Dan

---

<div class="post-metadata">

**Author:** ![dansinker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/65b543/32.png) [@dansinker](https://www.ruby-forum.com/u/dansinker)\
**Post date:** [June 25, 2009, 9:51pm UTC](https://www.ruby-forum.com/t/how-to-get-date-select-to-default-to-unused-date/171054/2 "2009-06-25T21:51:37Z")

</div>

> **[ActionView::Helpers::DateHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html)**
>
> Action View Date Helpers The Date Helper primarily creates select/option tags for different kinds of dates and times or date and time elements.

see the options list, :default

Gavin

> **[Ruby on Rails tips & Tutorials](https://handyrailstips.com)**
>
> Ruby on Rails tips and tutorials

---

<div class="post-metadata">

**Author:** ![dansinker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/65b543/32.png) [@dansinker](https://www.ruby-forum.com/u/dansinker)\
**Post date:** [June 26, 2009, 8:02pm UTC](https://www.ruby-forum.com/t/how-to-get-date-select-to-default-to-unused-date/171054/3 "2009-06-26T20:02:28Z")

</div>

Hmmm. So I did this:

\<%= date\_select (‘story’, ‘rundate’, :default =\> nil) %\>

and it didn’t do anything–the date select still shows today’s date.

Of course, the “nil” was a wild guess, so I tried the 3.days.from\_now  
that’s in the example and it also showed today’s date.

So, what am I doing wrong?

Thanks!!!

---

<div class="post-metadata">

**Author:** ![dansinker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/65b543/32.png) [@dansinker](https://www.ruby-forum.com/u/dansinker)\
**Post date:** [July 1, 2009, 4:55am UTC](https://www.ruby-forum.com/t/how-to-get-date-select-to-default-to-unused-date/171054/4 "2009-07-01T04:55:09Z")

</div>

Still hoping for some help with this:

I want date\_select to automatically default to the next available  
calendar date–my app schedules things in advance, so that date may be  
a ways away.

I can’t seem to figure out how to do this.

Bonus complication: How would I get it to skip weekends in this  
process

---

<div class="post-metadata">

**Author:** ![dansinker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/65b543/32.png) [@dansinker](https://www.ruby-forum.com/u/dansinker)\
**Post date:** [July 1, 2009, 4:05pm UTC](https://www.ruby-forum.com/t/how-to-get-date-select-to-default-to-unused-date/171054/5 "2009-07-01T16:05:15Z")

</div>

On Fri, Jun 26, 2009 at 1:46 PM, sinker[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So, what am I doing wrong?  
> Does @story.rundate already have a value? I’m pretty sure that the  
> :default option only applies if the attribute is not already set.

If you are editing an existing story then I’d think you’d want to  
initialize the select to the current value.

If you’re creating a new story, then I think you want to initialize a  
new Story to have the rundate attribute set to the next open date  
before rendering the view.

Now how you calculate that next open date is a matter of your own domain  
logic.

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)
