# Date\_select oddness

**URL:** <https://www.ruby-forum.com/t/date-select-oddness/49086>\
**Category:** Rails\
**Created:** [November 29, 2005, 5:58pm UTC](https://www.ruby-forum.com/t/date-select-oddness/49086 "2005-11-29T17:58:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![openbsdpl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a88e4f/32.png) [@openbsdpl](https://www.ruby-forum.com/u/openbsdpl)\
**Post date:** [November 29, 2005, 5:58pm UTC](https://www.ruby-forum.com/t/date-select-oddness/49086/1 "2005-11-29T17:58:35Z")

</div>

Hello,  
I have a problem when with this tag in view:  
\<%= date\_select :customdate, nil %\>

In the controller there is:  
d = Date.new  
d = params[:customdate]  
render\_text “#{d.inspect}”

The problem is the :customdate doesnt get transformed  
into Date, instead I get this:  
{"(3i)"=\>“29”, “(1i)”=\>“2005”, “(2i)”=\>“11”}

Any ideas how to solve it?

Best regards,  
Tom

---

<div class="post-metadata">

**Author:** ![openbsdpl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a88e4f/32.png) [@openbsdpl](https://www.ruby-forum.com/u/openbsdpl)\
**Post date:** [November 29, 2005, 8:03pm UTC](https://www.ruby-forum.com/t/date-select-oddness/49086/2 "2005-11-29T20:03:37Z")

</div>

openbsdpl wrote:

> Hello,  
> I have a problem when with this tag in view:  
> \<%= date\_select :customdate, nil %\>
> 
> In the controller there is:  
> d = Date.new  
> d = params[:customdate]  
> render\_text “#{d.inspect}”
> 
> The problem is the :customdate doesnt get transformed  
> into Date, instead I get this:  
> {"(3i)"=\>“29”, “(1i)”=\>“2005”, “(2i)”=\>“11”}
> 
> Any ideas how to solve it?
> 
> Best regards,  
> Tom

Shouldn’t it be:

d = Date.new( params[:customdate] )

??

---

<div class="post-metadata">

**Author:** ![openbsdpl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a88e4f/32.png) [@openbsdpl](https://www.ruby-forum.com/u/openbsdpl)\
**Post date:** [November 30, 2005, 1:35pm UTC](https://www.ruby-forum.com/t/date-select-oddness/49086/3 "2005-11-30T13:35:30Z")

</div>

jonathan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) napisaÅ?(a):

> > 
> 
> ??  
> Nope. This throws an error:  
> NoMethodError in Forms#korpus\_create\_row

undefined method `-’ for {“(3i)”=\>“30”, “(1i)”=\>“2005”,  
“(2i)”=\>“11”}:HashWithIndifferentAccess

c:/ruby/lib/ruby/1.8/date.rb:297:in `civil_to_jd' c:/ruby/lib/ruby/1.8/date.rb:568:in `valid\_civil?’  
c:/ruby/lib/ruby/1.8/date.rb:590:in `new' #{RAILS_ROOT}/app/controllers/forms_controller.rb:279:in `korpus\_create\_row’

---

<div class="post-metadata">

**Author:** ![openbsdpl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a88e4f/32.png) [@openbsdpl](https://www.ruby-forum.com/u/openbsdpl)\
**Post date:** [December 3, 2005, 2:17pm UTC](https://www.ruby-forum.com/t/date-select-oddness/49086/4 "2005-12-03T14:17:43Z")

</div>

Tomasz B±k w:

> Hello,  
> I have a problem when with this tag in view:  
> \<%= date\_select :customdate, nil %\>  
> I have changed it into:  
> \<%= date\_select :row, :customdate %\>

> The problem is the :customdate doesnt get transformed  
> into Date, instead I get this:  
> {"(3i)"=\>“29”, “(1i)”=\>“2005”, “(2i)”=\>“11”}  
> With this little function

def date\_select\_to\_date(struct,name)  
Date.new(struct["#{name}(1i)"].to\_i,  
struct["#{name}(2i)"].to\_i,  
struct["#{name}(3i)"].to\_i)  
end

I can get the date in the controller:

d = date\_select\_to\_date(params[:row],'customdate ')

Tom.
