【发布时间】:2018-05-22 15:46:23
【问题描述】:
您好,我对 ruby on rails 很陌生,所以请放轻松。我有一个 Rails 应用程序,其中包含一个显示记录的表格。我有一个按日期过滤表格结果的搜索栏。我的搜索栏选择标签是这样的
select_tag :date, options_for_select(@previous_summary_history_dates.uniq), prompt: "Search by date", id: "summary-history-date-filter", class: "form-control"
这是我在控制器中的@previous_summary_history_dates,选择标签从中获取值
@previous_summary_history_dates = SummarySheet.where(is_history: nil).pluck(:record_inserted_at).map{|a| a.strftime("%m/%d/%Y - %l:%M %p")}.uniq
我已将application.rb 文件设置为此
config.time_zone = 'Pacific Time (US & Canada)'
config.active_record.default_timezone = :local
我有一个搜索栏的查询,它显示表中按从选择标记中选择的日期过滤的记录,类似于这样
@summary_history = SummarySheet.where(record_inserted_at: DateTime.strptime(params[:date], "%m/%d/%Y - %l:%M %p").at_beginning_of_minute..DateTime.strptime(params[:date], "%m/%d/%Y - %l:%M %p").at_end_of_minute)
此查询有效,但它以 UTC 格式为我提供了与我的选择标签的 PCT 格式不匹配的输出,我得到的结果为空。如果我将我的选择标签时区更改为 UTC,我会得到所需的输出。
我尝试在过滤器查询中使用.in_time_zone("Pacific Time (US & Canada)") 来转换 PCT 中的日期,但没有成功
有人可以建议我如何将选择标签保留在 PCT 中并触发查询并仍然获得日期过滤输出?提前致谢
【问题讨论】:
标签: postgresql datetime ruby-on-rails-5 rails-activerecord