如何使Rails时间选择仅显示小时部分而不显示分钟?基本上,我想要的是显示一个带有start_time和end_time的时间过滤器,并使用Ransack gem来过滤查询。
# db
create_table "schedules"
t.time "start_time"
t.time "end_time"
# controller
@q = Schedule.ransack(params[:q])
@q.sorts = ['date asc', 'start_time asc', 'end_time asc'] if @q.sorts.empty?
@schedules = @q.result.includes(:klass, :partner, :city)
#view
<%= search_form_for @q do |f| %>
<%= f.label :start_time_gteq, "Start time" %>
<%= f.select_hour :start_time_gteq, start_hour: 5, end_hour: 23 %>
<%= f.submit "Filter" %>
<% end %>但它给了我一个错误:
undefined method `select_hour' for #<Ransack::Helpers::FormBuilder:0x007fb85217e000>我也试过:
<%= f.time_select :start_time_eq, start_hour: 5, end_hour: 23 %>...but它显示了分钟的部分。我向API接口查询过,但是没有办法只显示time_select的几个小时。
编辑:
显然,有一种方法可以移除小部分:
<%= f.time_select :start_time_gteq, discard_minute: true %>不幸的是,它也会生成默认为系统当前分钟的隐藏输入标记,这使得过滤变得无用。
发布于 2015-06-23 18:19:28
也许是时候生成您自己的自定义选择,而不是试图强制安装Rails助手.也许是这样的:
<%= f.label "start_hour_eq", "Start time" %>
<%= f.select "start_hour_eq", (5..23).to_a %>:00取决于所期望的输入,您可能需要调整名称和/或在会议记录中包含一个隐藏字段:
= hidden_field_tag "start_minute_eq", 0发布于 2018-12-10 09:31:13
怎么样:小时
select_hour(datetime,options = {},html_options = {}) public
返回一个select标记,其中包含每个小时的选项(从0小时到23小时),并选择当前小时。
https://stackoverflow.com/questions/31008666
复制相似问题