Forum: Ruby on Rails Working with date_select ...

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.
896c4e431b2225543c75114e3e9c9b97?d=identicon&s=25 Dale Martenson (Guest)
on 2006-02-28 03:03
(Received via mailing list)
I am a little confused about the best way to work with date_select. I
see that
in my views it generates a simple input form that allows for the entry
of year,
month and date information. If I just leave it at that, great!

But what if now in the controller, I want to work with the date
information. I
actually want to take the user input date and compute a new date some
number of
days in the future.

How should I use "start_date(1i), start_date(2i), start_date(3i)" in a
controller to fill in a new SQL date column?

Does there exist helpers to convert from "start_date(1i),
start_date(2i),
start_date(3i)" to a Ruby Class like Date or Time?

Page 203 of "Agile Web Development with Rails" implies that SQL Types
like
"interval, date" are mapped to the Ruby Class "Date" and the SQL Types
"datetime, time" are mapped to the Ruby Class "Time". Why isn't it that
date_select returns a Date object?

Thanks in advance for setting my understanding straight in this matter.

--Dale
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2006-02-28 21:09
(Received via mailing list)
Dale Martenson wrote:
>
> Does there exist helpers to convert from "start_date(1i), start_date(2i),
> start_date(3i)" to a Ruby Class like Date or Time?
>
> Page 203 of "Agile Web Development with Rails" implies that SQL Types like
> "interval, date" are mapped to the Ruby Class "Date" and the SQL Types
> "datetime, time" are mapped to the Ruby Class "Time". Why isn't it that
> date_select returns a Date object?

If start_date is an Active Record column of type Date it will be
automatically set from the three parameters when you call either
Model.new(params) or model_instance.update_attributes(params).

If however start_date is an attr_accessor in the model, you'll have
to use the select_date helper instead.


--
We develop, watch us RoR, in numbers too big to ignore.
This topic is locked and can not be replied to.