Reputation: 1323
I have a time field in my database. I want to have a time select field to select the time as three drop downs, for a 12-hour clock. One drop down is to select the hours from 1 to 12, the second drop down is to select the minutes from 1 to 59, and the third drop down is to select the AM or PM, for a single time field column in database. I have searched for this kind of time helper, but I did't find one. Is there any way to customize the time select helper to select the time format in this way in Rails?
Upvotes: 0
Views: 1208
Reputation: 2383
There is not a built-in Rails helper that will add a separate select field for choosing between AM/PM. However, the time_select
helper will allow you to select time in hours, minutes, AM/PM as you asked. This would most likely also be the suggested "Rails way" of accomplishing this. You can use the :ampm
option to display hours as "12 PM", "01 AM", etc.
time_select 'game', 'game_time', {:ampm => true}
See the time_select
documentation page for more info.
Upvotes: 1