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)