Forum: Ruby on Rails date_select oddness

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
openbsdpl (Guest)
on 2005-11-29 18:58
(Received via mailing list)
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
jonathan <> (Guest)
on 2005-11-29 21:03
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] )

??
openbsdpl (Guest)
on 2005-11-30 14:35
(Received via mailing list)
jonathan <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'
openbsdpl (Guest)
on 2005-12-03 15:17
(Received via mailing list)
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.
This topic is locked and can not be replied to.