如何在rails活动记录中的日期上指定小于今天的条件 [英] How to specify a less than today condition on a date in rails active record

查看:135
本文介绍了如何在rails活动记录中的日期上指定小于今天的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图弄清楚如何拉出我的集合中的所有记录,其中发布字段为真,过期小于今天。我有以下但我不认为不到部分工作,有人可以指出我在正确的轨道上?

I'm trying to figure out how to pull all the records in my set where their fields "publish" is true and "expires" is less than today. I have the following but i dont think the less than part is working, can someone please point me on the right track?

  @announcements = Announcement.where(:publish => true, :expires < Date.today)

在此先感谢您的帮助

推荐答案

试试这个:

@announcements = Announcement.where("publish = ? AND expires < ?", true, Date.today)

这篇关于如何在rails活动记录中的日期上指定小于今天的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆