【问题标题】:Strip undesired values from Rails' time_select()从 Rails 的 time_select() 中去除不需要的值
【发布时间】:2014-04-11 11:08:45
【问题描述】:

谁能指出我从 Ruby on Rails time_select 中去除不需要的值的解决方案?

基本上,time_select 显示从 0024 的所有时间,但在我的应用程序中,我需要防止用户直接在 SELECT 标记中选择 08 之前和 16 之后的时间,而且似乎没有是我可以传递给time_select的相应选项。

【问题讨论】:

    标签: ruby-on-rails ruby time


    【解决方案1】:

    您可以使用select_timeselect_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 之间的时间。

    【讨论】:

      【解决方案2】:
      select_time(my_time, start_hour: 8, end_hour: 16)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-05-14
        • 2016-02-28
        • 1970-01-01
        • 2010-10-20
        • 1970-01-01
        • 2011-06-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多