【发布时间】:2014-04-11 11:08:45
【问题描述】:
谁能指出我从 Ruby on Rails time_select 中去除不需要的值的解决方案?
基本上,time_select 显示从 00 到 24 的所有时间,但在我的应用程序中,我需要防止用户直接在 SELECT 标记中选择 08 之前和 16 之后的时间,而且似乎没有是我可以传递给time_select的相应选项。
【问题讨论】:
标签: ruby-on-rails ruby time
谁能指出我从 Ruby on Rails time_select 中去除不需要的值的解决方案?
基本上,time_select 显示从 00 到 24 的所有时间,但在我的应用程序中,我需要防止用户直接在 SELECT 标记中选择 08 之前和 16 之后的时间,而且似乎没有是我可以传递给time_select的相应选项。
【问题讨论】:
标签: ruby-on-rails ruby time
您可以使用select_time 或select_hour。
select_time(my_time, start_hour: 8, end_hour: 16) # Generates a time select field with hours that range from 8 to 16
select_hour(my_time, start_hour: 8, end_hour: 16) # Generates a time select field with hours that range from 8 to 16
这样就限制了用户选择 8 到 16 之间的时间。
【讨论】:
select_time(my_time, start_hour: 8, end_hour: 16)
【讨论】: