# Date\_select and selected options

**URL:** <https://www.ruby-forum.com/t/date-select-and-selected-options/140761>\
**Category:** Rails\
**Created:** [June 18, 2008, 11:27am UTC](https://www.ruby-forum.com/t/date-select-and-selected-options/140761 "2008-06-18T11:27:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![acgreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3bc359/32.png) [@acgreen](https://www.ruby-forum.com/u/acgreen)\
**Post date:** [June 18, 2008, 11:27am UTC](https://www.ruby-forum.com/t/date-select-and-selected-options/140761/1 "2008-06-18T11:27:57Z")

</div>

I can accept the dob date from the \_form partial and insert into the DB.  
But when I want to display the date as selected in the \_form partial,  
I’m hitting a wall. Googling hasn;t helped.

\_form.rhtml  
\<%= date\_select ‘date’, ‘dob’, :order =\> [:day,:month,:year],  
:start\_year =\> 1930,Â :include\_blank =\> true%\>

##Parameters: {“commit”=\>“Create”, “date”=\>{“dob(1i)”=\>“1938”,  
“dob(2i)”=\>“5”, “dob(3i)”=\>“8”}

## logger.debug( params[:date].class ) displays

HashWithIndifferentAccess

## accessing no problems

yearÂ = params[:date][‘dob(1i)’]  
month = params[:date][‘dob(2i)’]  
dayÂ Â = params[:date][‘dob(3i)’]

The two ways I’ve tried to set the selected option with different  
results are as follows …

## setting selected values

dob = @client.dob.split(/-/)  
@date = HashWithIndifferentAccess.new()  
@date[‘dob(1i)’] = dob[0]  
@date[‘dob(2i)’] = dob[1]  
@date[‘dob(3i)’] = dob[2]

## error log

ActionView::TemplateError (undefined method `dob’ for {“(3i)”=\>“17”,  
“year”=\>“2008”, “(2i)”=\>“6”}:HashWithIndifferentAccess) on line #18 of  
app/views/client/\_form.rhtml:  
15:Â Â   
16:Â Â   
17:Â Â Â Â DOB  
18:Â Â Â Â \<%= date\_select ‘date’, ‘dob’, :order =\>  
[:day,:month,:year], :start\_year =\> 1930 %\>  
19:Â Â   
20:Â Â \<!–  
21:Â Â

… and the other …  
\_form.rhtml  
\<%= date\_select ‘date’, ‘’, :order =\> [:day,:month,:year], :start\_year  
=\> 1930,Â :include\_blank =\> true%\>

##Parameters: {“commit”=\>“Create”, “date”=\>{“(1i)”=\>“1938”, “(2i)”=\>“5”,  
“(3i)”=\>“8”}

## logger.debug( params[:date].class ) displays

HashWithIndifferentAccess

## accessing no problems

yearÂ = params[:date][‘(1i)’]  
month = params[:date][‘(2i)’]  
dayÂ Â = params[:date][‘(3i)’]

## setting selected values

dob = @client.dob.split(/-/)  
@date = HashWithIndifferentAccess.new()  
@date[‘(1i)’] = dob[0]  
@date[‘(2i)’] = dob[1]  
@date[‘(3i)’] = dob[2]

## error log

ActionView::TemplateError (interning empty string) on line #18 of  
app/views/client/\_form.rhtml:  
15:Â Â   
16:Â Â   
17:Â Â Â Â DOB  
18:Â Â Â Â \<%= date\_select ‘date’, ‘’, :order =\> [:day,:month,:year],  
:start\_year =\> 1930, :include\_blank =\> trueÂ %\>  
19:Â Â   
20:Â Â \<!–  
21:Â Â

Any pointers from anyone?

CIA

-Ants

Disclaimer: Technically speaking, I am always wrong!

```
  __________________________________________________________

```

Sent from Yahoo! Mail.  
A Smarter Email [http://uk.docs.yahoo.com/nowyoucan.html](http://uk.docs.yahoo.com/nowyoucan.html)
