Rails : simple_for_for 12 小时格式的时间

Rails : simple_for_for time with 12 hour format

在 Rail 的 simple_for_for 中是否有正确的方法来显示 12 小时制?我目前正在使用

<%= f.input :time, :ampm => true, :minute_step => 5 %>

但是它只显示两个下拉菜单,时间在第一个下拉菜单中显示为 01AM,在第二个下拉菜单中显示为 00

我希望它有三个下拉菜单,分别代表小时、分钟和 am/pm。

根据 documentation

HTML 5 date / time inputs are not generated by Simple Form by default, so using date, time or datetime will all generate select boxes using normal Rails helpers. We believe browsers are not totally ready for these yet, but you can easily opt-in on a per-input basis by passing the html5 option:

<%= f.input :time, as: :time, html5: true %>

这应该可以解决您的问题。