Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 基于小时的ActiveRecord作用域_Ruby On Rails_Ruby_Postgresql - Fatal编程技术网

Ruby on rails 基于小时的ActiveRecord作用域

Ruby on rails 基于小时的ActiveRecord作用域,ruby-on-rails,ruby,postgresql,Ruby On Rails,Ruby,Postgresql,迭代 <% @challenges.with_exact.each do |challenge| %> etc... <% end %> 一些挑战将有一个nilexact 如何仅在Time.zone.now.strftime('%H')==challenge.exact.strftime('%H')的位置迭代质询?您可以使用postgres函数: where("date_part('hour', exact) = ?", Time.zone.now.hour) 这里

迭代

<% @challenges.with_exact.each do |challenge| %>
 etc...
<% end %>
一些挑战将有一个
nil
exact

如何仅在
Time.zone.now.strftime('%H')==challenge.exact.strftime('%H')的位置迭代质询?您可以使用postgres函数:

where("date_part('hour', exact) = ?", Time.zone.now.hour)
这里还有
等等

还有另一种方法

您可以使用postgres功能:

where("date_part('hour', exact) = ?", Time.zone.now.hour)
这里还有
等等

还有另一种方法


exact的类型是
datetime
time
?@Pavan看起来像是,
challenge.exact.strftime('%H')
。exact的类型是
datetime
time
?@Pavan看起来像是,
challenge.exact.strftime('%H')
where("extract(hour from exact) = ?", Time.zone.now.hour)