我正在尝试返回前天的记录。我的记录有带有日期和时间的 date created_at 列。而我的条件只有日期,所以它总是不返回任何记录。
我在 sqlite 上的开发中使用 strftime 删除了时间,但请问我如何在 PG 上进行实时操作?
@articles = Article.where("created_at = ?", Date.yesterday-(params[:increment].to_i)).reverse
(增量=前天的天数。)
非常感谢
最佳答案
在当前的 Rails 版本中(从 5.1 版开始),您可以使用 all_day
helper对于这样的查询:
date = (params[:increment].to_i + 1).days.ago
Article.where(created_at: date.all_day).reverse
关于ruby-on-rails - 比较 rails Active Record 和 PG 中的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44749008/