How do I set up Rails time to show only the hour part without minutes? Basically, I want to show a time filter with start_time and end_time and use a Ransack gem to filter the request.
# 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 %>
But this gives me this error:
undefined method `select_hour' for #<Ransack::Helpers::FormBuilder:0x007fb85217e000>
I also tried:
<%= f.time_select :start_time_eq, start_hour: 5, end_hour: 23 %>
... but he shows the minute part. I checked with the API , but there is no way to show only hours with time_select .
EDIT:
There seems to be a way to remove the minute part:
<%= f.time_select :start_time_gteq, discard_minute: true %>
Unfortunately, it also generates hidden input tags, which by default do not match the current minute, which made filtering useless.
source share