Rails 4 + Ransack: lteq not working with datetime?

I have a ransack search form:

<h1>Scheduled Payments</h1>


<%= search_form_for [:admin, @search] do |form| %>
  <%= form.text_field :start_date_gteq, value: @order_date_gteq_with_proper_format, class: "datepicker" %> to
  <%= form.text_field :start_date_lteq, value: @order_date_lteq_with_proper_format, class: "datepicker" %>
  <%= form.submit "Search" %>
<% end %>

I want the user to be able to enter 2 dates, and for each record ScheduledPaymentwith start_date greater than or equal to the 1st text field AND start_date less than or equal to the second text field to display.

It works:

enter image description here

Please note that this entry has a start date 07/17/2014. When I type 07/17/2014in the second text box, nothing is displayed:

enter image description here

I assume that the hours or minutes in the start_date of this record are greater than +00: 00: 00, which is probably used as the default value for the second field. In this case, how would I capture all records from start_date 07/01/2014to 07/17/2014 23:59:59(absolute end 07/17/2014)?

+4
1

?

# the controller action where you pass the params to the search method:
def your_action
  start_time = params[:start_date_gteq].to_date rescue Date.current
  start_time = start_time.beginning_of_day # sets to 00:00:00
  end_time = params[:start_date_lteq].to_date rescue Date.current
  end_time = end_time.end_of_day # sets to 23:59:59
  ScheduledPayment.search(start_time: start_time..end_time)
+2

All Articles