Forum: Ruby on Rails Overriding date helpers in a logical way

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Matt T. (Guest)
on 2006-03-07 10:50
(Received via mailing list)
Short story: I need to use a different style of inputs to enter
datetimes. What I want is to be able to implement these while still
retaining the niceties of the built-in input helpers, like
ActiveRecord error handling and automatic reconstitution of a single
Date object from multiple form elements. What's the best way to go
about this?

Long story: My form has one standard month <select> input, a 2
character text <input> for year, a similar text <input> for both hour
and minute, a <select> for AM/PM and, the coup de'grĂ¢ce: two more text
<input>s for a second time that my app will calculate date 2 our of
based off of date 1.

Anyway, I was thinking of simply overriding the select_xxx() methods
in DateHelper, but they're all geared around <select> tags and I'm not
sure how much of the class hierarchy I'll have to dig up to get a
similar method but with <input>. Also, (and correct me if I'm wrong,)
the select_xxx methods don't support highlighting themselves on
ActiveRecord errors since they're not bound to any specific model
object. So I would have to add that to my own method, too. And I can't
just override datetime_select since my fields need to be flexibly
positioned, and not just one big <div>.

Ideally, I'd just do something like my_day_input(@date1),
my_hour_input(@date1), my_minute_input(@date1) and then just access
@date1 in the receiving controller method and have it be a valid Date.

So if you had to implement the above, how would you go about doing it?
I'm having trouble getting a foothold in this seemingly complex
-Matt T.
This topic is locked and can not be replied to.