How to create a custom time select form element?

Hello,

I would like to turn a regular 24 hour time select input into a 12 hour
time select with an additional AM/PM select input. For example:

Before:

[00…23] : [00…59]

After:

[1…12] : [00…59] [AM,PM]

I’m really surprised that this sort of thing doesn’t come standard in
Rails. Has this been
done before? Is there a plugin or gem that I can install? If not, how
can I create this from scratch?

Thanks,
Andrew

Why not just write your own html? A lot of this rails stuff is
ridiculously complicated for the simple html it produces.

I could easily write the HTML to create a few select elements, however,
it’s the Ruby part that I am not as familiar with. Could you provide an
example of what the controller code (or model, helper, etc) would look
like to convert the 3 fields into a valid time value ready to store in a
database?

I highly recommend using jQueryUI Datepicker for more usable date
selection.
However, if you want to have it your way, create fields in your model
for
all the select boxes, and use the before_save callback to construct the
final date field for storing in the database.

Refer Action View Form Helpers — Ruby on Rails Guides

On 14 August 2011 07:42, Andrew [email protected] wrote:

I could easily write the HTML to create a few select elements, however, it’s the
Ruby part that I am not as familiar with. Could you provide an example of what the
controller code (or model, helper, etc) would look like to convert the 3 fields
into a valid time value ready to store in a database?

Just take the params values and convert them into a Time object.
Time.utc or Time.local may be useful.

Colin

however, it’s the Ruby part that I am not as familiar with.

Then it’s time to put rails away and buy a beginning ruby book.

The Ruby P.ming Language by Matz is my personal favorite. You might
want to try that.