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?
Asked
Active
Viewed 1,062 times
1 Answers
1
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.

Dave Powers
- 2,051
- 2
- 30
- 34
-
i want to take the three dropdowns as i menctioned, and in controller can i construct a time object so that i can save this to time field, by passing these strings(hours, minutes,am/pm) ? – John Aug 03 '15 at 14:36